Advertisement
Guest User

DistanceCheck

a guest
Jan 30th, 2017
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. // @Maxpro 2017
  2.  
  3. #include "CodeTests.h"
  4. #include "SpiderAIController.h"
  5. #include "BehaviorTree/BlackboardComponent.h"
  6. #include "Task_DistanceCheck.h"
  7.  
  8. EBTNodeResult::Type UTask_DistanceCheck::ExecuteTask(UBehaviorTreeComponent & OwnerComp, uint8 * NodeMemory)
  9. {
  10.  
  11. Super::ExecuteTask(OwnerComp, NodeMemory);
  12.  
  13.  
  14. NodeName = ThisNodeName;
  15.  
  16.  
  17. ASpiderAIController* AICon = Cast<ASpiderAIController>(OwnerComp.GetAIOwner());
  18.  
  19. if (AICon)
  20. {
  21. UBlackboardComponent* BlackboardComp = AICon->GetBlackboardComp();
  22. if (BlackboardComp)
  23. {
  24. float AttackRange = BlackboardComp->GetValueAsFloat("AttackRange");
  25. int AtkRange = AttackRange;
  26. // need a way to get this info without having to set the pawn beforehand
  27.  
  28. FVector Location = AICon->GetPawn()->GetActorLocation() - (Cast<AActor>(BlackboardComp->GetValueAsObject("Player"))->GetActorLocation());
  29.  
  30. //GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Red, Location.ToString());
  31. float VectorLength = Location.Size();
  32. int len = VectorLength;
  33. GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Red, FString::FromInt(len));
  34. GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Red, FString::FromInt(AtkRange));
  35.  
  36.  
  37.  
  38. if (AttackRange >= VectorLength)
  39. {
  40. BlackboardComp->SetValueAsBool("InAttackRange", true);
  41. }
  42. else
  43. {
  44.  
  45. }
  46. }
  47. }
  48. return EBTNodeResult::Succeeded;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement