// Copyright Zelle Games #include "MoveToRandomSpot.h" #include "AIController.h" #include "NavigationSystem.h" EBTNodeResult::Type UMoveToRandomSpot::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) { bNotifyTick = 1; FNavLocation Loc; UNavigationSystemV1* NavSystem = UNavigationSystemV1::GetCurrent(GetWorld()); NavSystem->GetRandomReachablePointInRadius(OwnerComp.GetAIOwner()->GetPawn()->GetActorLocation(), 8000, Loc); OwnerComp.GetAIOwner()->MoveToLocation(Loc.Location); return EBTNodeResult::InProgress; } void UMoveToRandomSpot::TickTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds) { TimeSinceExecute += DeltaSeconds; if(TimeSinceExecute > 2) { FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded); } }