FVector ABaseController::GetNewSearchPosition()
{
	FNavLocation Location;
	UNavigationSystem* NavSys = World->GetNavigationSystem();
	NavSys->GetRandomPointInNavigableRadius(TargetsLastKnownPosition, Self->SearchRange, Location);
	return Location.Location;
}
FVector ABaseController::GetHitPosition()
{
	FNavLocation location;
	UNavigationSystem* navSys = UNavigationSystem::GetCurrent(World);
	navSys->GetRandomPointInNavigableRadius(AttackLocation, 200.f, location);
	return location.Location;
}
FVector ABaseController::GetNewWanderPosition()
{
	FNavLocation Location;
	UNavigationSystem* NavSys = World->GetNavigationSystem();

	FHitResult hit(ForceInit);
	FCollisionQueryParams traceParams = FCollisionQueryParams(FName(TEXT("RV_Trace")), true, Self);
	traceParams.bTraceComplex = true;
	traceParams.bTraceAsyncScene = true;

	int times = 0;
	float minimuimDist = Self->MinimuimDistanceBetweenWanderLocations;

	do{
		if (times >= 50)
		{
			times = 0;
			minimuimDist -= 500.f;
		}

		times++;
		NavSys->GetRandomPointInNavigableRadius(Self->GetActorLocation(), Self->SightRange, Location);
	} while (FVector::Dist(Location.Location, Self->GetActorLocation()) < minimuimDist);

	bool bHit = World->LineTraceSingleByChannel(hit, Self->EyeLocation, Location.Location, ECC_Visibility, traceParams);

	return Location.Location;
}
Esempio n. 4
0
EBTNodeResult::Type UATBTTask_MoveArea::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	UNavigationSystem* NavigationSystem = UNavigationSystem::GetCurrent(GetWorld());
	AATCharacterAI* MyCharacter = Cast<AATCharacterAI>(OwnerComp.GetAIOwner()->GetPawn());

	if (NavigationSystem != nullptr && MyCharacter != nullptr)
	{
		FNavLocation RandomPointIn;
		if (NavigationSystem->GetRandomPointInNavigableRadius(MyCharacter->GetActorLocation(), MyCharacter->AreaRadius, RandomPointIn))
		{
			OwnerComp.GetBlackboardComponent()->SetValue<UBlackboardKeyType_Vector>(GetSelectedBlackboardKey(), RandomPointIn.Location);
			return EBTNodeResult::Succeeded;
		}
	}
	return EBTNodeResult::Failed;
}