Esempio n. 1
0
void AZanshinAIController::SetLocation()
{
	ATargetPoint* NewTarget = LocationsToWalk[PathIndex];
	if (NewTarget)
	{
		FVector NewLocation = NewTarget->GetActorLocation();
		BlackboardComponent->SetValue<UBlackboardKeyType_Vector>(LocationID, NewLocation);
	}
}
EBTNodeResult::Type UBTTask_FindPointNearWaypoint::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	AsbrAIController* aiController = Cast<AsbrAIController>(OwnerComp.GetAIOwner());
	if (aiController == NULL)
		return EBTNodeResult::Failed;

	ATargetPoint* waypoint = aiController->GetWaypoint();
	if (waypoint)
	{
		const float SearchRadius = 200.0f;
		const FVector SearchOrigin = waypoint->GetActorLocation();
		const FVector Loc = UNavigationSystem::GetRandomPointInNavigableRadius(aiController, SearchOrigin, SearchRadius);
		if (Loc != FVector::ZeroVector)
		{
			OwnerComp.GetBlackboardComponent()->SetValue<UBlackboardKeyType_Vector>(BlackboardKey.GetSelectedKeyID(), Loc);
			aiController->SetWaypointVisited(waypoint);	// сообщаем что посетили waypoint (todo: надо учесть расстояние)
			return EBTNodeResult::Succeeded;
		}
	}

	return EBTNodeResult::Failed;
}