Space Plunder
Loading...
Searching...
No Matches
UBTD_DistanceTo Class Reference

A behavior tree decorator that checks the distance between the owner and the target actor. More...

#include <BTD_DistanceTo.h>

Inheritance diagram for UBTD_DistanceTo:

Public Member Functions

 UBTD_DistanceTo ()
 

Protected Member Functions

virtual FString GetStaticDescription () const override
 
virtual bool CalculateRawConditionValue (UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory) const override
 
virtual void TickNode (UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory, float DeltaSeconds) override
 

Protected Attributes

FBlackboardKeySelector TargetActor
 
float MaxDistance = 100.0f
 

Detailed Description

A behavior tree decorator that checks the distance between the owner and the target actor.

This decorator calculates the distance between the owner (controlled AI) and the target actor (specified in the blackboard). If the distance is less than or equal to the maximum distance, the condition is considered true. Otherwise, the condition is considered false.

Constructor & Destructor Documentation

◆ UBTD_DistanceTo()

UBTD_DistanceTo::UBTD_DistanceTo ( )
15{
16 NodeName = TEXT("Check Distance");
17 INIT_DECORATOR_NODE_NOTIFY_FLAGS();
18}

Member Function Documentation

◆ CalculateRawConditionValue()

bool UBTD_DistanceTo::CalculateRawConditionValue ( UBehaviorTreeComponent & OwnerComp,
uint8 * NodeMemory ) const
overrideprotectedvirtual
45{
46 if(OwnerComp.GetAIOwner() == nullptr || OwnerComp.GetAIOwner()->GetPawn() == nullptr){return false;}
47
48 const FVector ActorLocation = OwnerComp.GetAIOwner()->GetPawn()->GetActorLocation();
49 const UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
50 if(BlackboardComp != nullptr)
51 {
52 FVector TargetLocation;
53 //- Try Get key as an Actor //
54 const AActor* ActorObject = Cast<AActor>(BlackboardComp->GetValueAsObject(TargetActor.SelectedKeyName));
55 if(ActorObject != nullptr)
56 {
57 TargetLocation = ActorObject->GetActorLocation();
58 }
59 //- Get key as a Vector //
60 else
61 {
62 TargetLocation = BlackboardComp->GetValueAsVector(TargetActor.SelectedKeyName);
63 }
64 const float Distance = (ActorLocation - TargetLocation).Length();
65 return (Distance <= MaxDistance);
66 }
67 return false;
68}
float MaxDistance
Definition BTD_DistanceTo.h:38
FBlackboardKeySelector TargetActor
Definition BTD_DistanceTo.h:36

◆ GetStaticDescription()

FString UBTD_DistanceTo::GetStaticDescription ( ) const
overrideprotectedvirtual
21{
22 FString Description;// = Super::GetStaticDescription();
23 Description += FString::Printf(TEXT("\nMax Distance: %i"), FMath::RoundToInt(MaxDistance));
24 if(TargetActor.SelectedKeyName.IsValid())
25 {
26 Description += FString::Printf(TEXT("\nTarget Actor: %s"), *TargetActor.SelectedKeyName.ToString());
27 }
28 else
29 {
30 Description += TEXT("\nTarget Actor: None");
31 }
32 // Description += FString::Printf(TEXT("\nMy Boolean Property: %s"), bMyBooleanProperty ? TEXT("True") : TEXT("False"));
33 return Description;
34}

◆ TickNode()

void UBTD_DistanceTo::TickNode ( UBehaviorTreeComponent & OwnerComp,
uint8 * NodeMemory,
float DeltaSeconds )
overrideprotectedvirtual
71{
72 TRACE_CPUPROFILER_EVENT_SCOPE(UBTD_DistanceTo::TickNode);
73 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Behaviors);
74 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Decorators);
75
76 Super::TickNode(OwnerComp, NodeMemory, DeltaSeconds);
77 if(CalculateRawConditionValue(OwnerComp, NodeMemory))
78 {
79 OwnerComp.RequestExecution(this);
80 }
81}
virtual void TickNode(UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory, float DeltaSeconds) override
Definition BTD_DistanceTo.cpp:70
virtual bool CalculateRawConditionValue(UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory) const override
Definition BTD_DistanceTo.cpp:44

Member Data Documentation

◆ MaxDistance

float UBTD_DistanceTo::MaxDistance = 100.0f
protected

◆ TargetActor

FBlackboardKeySelector UBTD_DistanceTo::TargetActor
protected

The documentation for this class was generated from the following files: