Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // @Maxpro 2017
- #include "CodeTests.h"
- #include "SpiderAIController.h"
- #include "BehaviorTree/BlackboardComponent.h"
- #include "Task_DistanceCheck.h"
- EBTNodeResult::Type UTask_DistanceCheck::ExecuteTask(UBehaviorTreeComponent & OwnerComp, uint8 * NodeMemory)
- {
- Super::ExecuteTask(OwnerComp, NodeMemory);
- NodeName = ThisNodeName;
- ASpiderAIController* AICon = Cast<ASpiderAIController>(OwnerComp.GetAIOwner());
- if (AICon)
- {
- UBlackboardComponent* BlackboardComp = AICon->GetBlackboardComp();
- if (BlackboardComp)
- {
- float AttackRange = BlackboardComp->GetValueAsFloat("AttackRange");
- int AtkRange = AttackRange;
- // need a way to get this info without having to set the pawn beforehand
- FVector Location = AICon->GetPawn()->GetActorLocation() - (Cast<AActor>(BlackboardComp->GetValueAsObject("Player"))->GetActorLocation());
- //GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Red, Location.ToString());
- float VectorLength = Location.Size();
- int len = VectorLength;
- GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Red, FString::FromInt(len));
- GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Red, FString::FromInt(AtkRange));
- if (AttackRange >= VectorLength)
- {
- BlackboardComp->SetValueAsBool("InAttackRange", true);
- }
- else
- {
- }
- }
- }
- return EBTNodeResult::Succeeded;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement