25{
27 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Behaviors);
28 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Tasks);
29
30 FBTTaskRotateMemory* RotateMemory = reinterpret_cast<FBTTaskRotateMemory*>(NodeMemory);
31 if(OwnerComp.GetAIOwner() == nullptr || OwnerComp.GetAIOwner()->GetPawn() == nullptr || RotateMemory == nullptr){return EBTNodeResult::Failed;}
32 RotateMemory->LookAroundCount = 1;
34
35
36 FVector ActorsEyeLocation;
37 FRotator ActorsEyeRotation;
38 OwnerComp.GetAIOwner()->GetPawn()->GetActorEyesViewPoint(ActorsEyeLocation, ActorsEyeRotation);
39
40
41 RotateMemory->StartRotation = ActorsEyeRotation;
42 RotateMemory->OriginalRotation = RotateMemory->StartRotation;
43 RotateMemory->StartLocation = ActorsEyeLocation;
44 RotateMemory->OriginalLocation = RotateMemory->StartLocation;
45
46
47 RotateMemory->RandomDeviationMultiplier = FMath::RandRange(0.0f,
RandomDeviation);
48
49
50 const FRotator TargetRotation = FRotator(ActorsEyeRotation.Pitch, (ActorsEyeRotation.Yaw +
RotationDegrees), ActorsEyeRotation.Roll);
51 const FRotator TargetOppositeRotation = FRotator(ActorsEyeRotation.Pitch, (ActorsEyeRotation.Yaw -
RotationDegrees), ActorsEyeRotation.Roll);
52
53
54
55 RotateMemory->FocalPoint = (ActorsEyeLocation + (ActorsEyeRotation.Vector() *
ForwardDistance));
56
57
58 RotateMemory->TargetLocation = (ActorsEyeLocation + (TargetRotation.Vector() *
ForwardDistance));
59 RotateMemory->TargetOppositeLocation = (ActorsEyeLocation + (TargetOppositeRotation.Vector() *
ForwardDistance));
60
62 {
63 if(AAIController* AIController = OwnerComp.GetAIOwner())
64 {
66 }
67 return EBTNodeResult::Succeeded;
68 }
69 return EBTNodeResult::InProgress;
70}
float ForwardDistance
Definition BTTask_Rotate.h:39
float RotationDegrees
Definition BTTask_Rotate.h:35
static void ResetNumbers(FBTTaskRotateMemory *RotateMemory)
Definition BTTask_Rotate.cpp:113
bool bInstantTurn
Definition BTTask_Rotate.h:41
void InstantTurn(const FBTTaskRotateMemory *RotateMemory, AAIController *AIController) const
Definition BTTask_Rotate.cpp:72
float RandomDeviation
Definition BTTask_Rotate.h:46
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory) override
Definition BTTask_Rotate.cpp:24