Advertisement
Guest User

TargetPointSelection

a guest
Apr 10th, 2020
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1.  
  2. #include "MyBTTaskTargetPointSelection.h"
  3. #include "SoldierAIController.h"
  4. #include "BehaviorTree/BlackboardComponent.h"
  5. #include "SoldierTargetPoint.h"
  6.  
  7. EBTNodeResult::Type UMyBTTaskTargetPointSelection::ExecuteTask(UBehaviorTreeComponent & OwnerComp, uint8 * NodeMemory)
  8. {
  9.     ASoldierAIController* AIController = Cast<ASoldierAIController>(OwnerComp.GetAIOwner());
  10.    
  11.     if (AIController)
  12.     {
  13.         UBlackboardComponent* BlackboardComp = AIController->GetBlackboardComp();
  14.         ASoldierTargetPoint* currentPoint = Cast<ASoldierTargetPoint>(BlackboardComp->GetValueAsObject("LocationToGo"));
  15.        
  16.         TArray<AActor*> AvailableTargetPoints = AIController->GetAvailableTargetPoints();
  17.    
  18.         int32 RandomIndex;
  19.  
  20.         ASoldierTargetPoint* NextTargetPoint = nullptr;
  21.  
  22.         do {
  23.             RandomIndex = FMath::RandRange(0, AvailableTargetPoints.Num() - 1);
  24.             NextTargetPoint = Cast<ASoldierTargetPoint>(AvailableTargetPoints[RandomIndex]);
  25.        
  26.         } while (currentPoint == NextTargetPoint);
  27.  
  28.         BlackboardComp->SetValueAsObject("LocationToGo", NextTargetPoint);
  29.        
  30.         AIController->isPatrolling = true;
  31.  
  32.         return EBTNodeResult::Succeeded;
  33.     }
  34.     return EBTNodeResult::Failed;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement