Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void UAIBlueprintHelperLibrary::SimpleMoveToLocation(AController* Controller, const FVector& GoalLocation)
- {
- UNavigationSystemV1* NavSys = Controller ? FNavigationSystem::GetCurrent<UNavigationSystemV1>(Controller->GetWorld()) : nullptr;
- if (NavSys == nullptr || Controller == nullptr || Controller->GetPawn() == nullptr)
- {
- UE_LOG(LogNavigation, Warning, TEXT("UNavigationSystemV1::SimpleMoveToActor called for NavSys:%s Controller:%s controlling Pawn:%s (if any of these is None then there's your problem"),
- *GetNameSafe(NavSys), *GetNameSafe(Controller), Controller ? *GetNameSafe(Controller->GetPawn()) : TEXT("NULL"));
- return;
- }
- UPathFollowingComponent* PFollowComp = InitNavigationControl(*Controller);
- if (PFollowComp == nullptr)
- {
- FMessageLog("PIE").Warning(FText::Format(
- LOCTEXT("SimpleMoveErrorNoComp", "SimpleMove failed for {0}: missing components"),
- FText::FromName(Controller->GetFName())
- ));
- return;
- }
- if (!PFollowComp->IsPathFollowingAllowed())
- {
- FMessageLog("PIE").Warning(FText::Format(
- LOCTEXT("SimpleMoveErrorMovement", "SimpleMove failed for {0}: movement not allowed"),
- FText::FromName(Controller->GetFName())
- ));
- return;
- }
- const bool bAlreadyAtGoal = PFollowComp->HasReached(GoalLocation, EPathFollowingReachMode::OverlapAgent);
- // script source, keep only one move request at time
- if (PFollowComp->GetStatus() != EPathFollowingStatus::Idle)
- {
- PFollowComp->AbortMove(*NavSys, FPathFollowingResultFlags::ForcedScript | FPathFollowingResultFlags::NewRequest
- , FAIRequestID::AnyRequest, bAlreadyAtGoal ? EPathFollowingVelocityMode::Reset : EPathFollowingVelocityMode::Keep);
- }
- // script source, keep only one move request at time
- if (PFollowComp->GetStatus() != EPathFollowingStatus::Idle)
- {
- PFollowComp->AbortMove(*NavSys, FPathFollowingResultFlags::ForcedScript | FPathFollowingResultFlags::NewRequest);
- }
- if (bAlreadyAtGoal)
- {
- PFollowComp->RequestMoveWithImmediateFinish(EPathFollowingResult::Success);
- }
- else
- {
- const ANavigationData* NavData = NavSys->GetNavDataForProps(Controller->GetNavAgentPropertiesRef());
- if (NavData)
- {
- FPathFindingQuery Query(Controller, *NavData, Controller->GetNavAgentLocation(), GoalLocation);
- FPathFindingResult Result = NavSys->FindPathSync(Query);
- if (Result.IsSuccessful())
- {
- PFollowComp->RequestMove(FAIMoveRequest(GoalLocation), Result.Path);
- }
- else if (PFollowComp->GetStatus() != EPathFollowingStatus::Idle)
- {
- PFollowComp->RequestMoveWithImmediateFinish(EPathFollowingResult::Invalid);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement