23{
25
26 if (!Data.Actor || !Data.TargetActor)
27 {
28 return EStateTreeRunStatus::Failed;
29 }
30
31 const FVector Velocity = Data.
Actor->GetVelocity();
32 if (Velocity.Size2D() > 10.0f)
33 {
34 return EStateTreeRunStatus::Running;
35 }
36
37 FVector LookAtDirection = Data.TargetActor->GetActorLocation() - Data.Actor->GetActorLocation();
38 LookAtDirection.Z = 0.0f;
39
40 if (LookAtDirection.IsNearlyZero())
41 {
42 return EStateTreeRunStatus::Running;
43 }
44
45 const FRotator CurrentRotation = Data.Actor->GetActorRotation();
46 const FRotator TargetRotation = LookAtDirection.Rotation();
47 const FRotator NewRotation = FMath::RInterpTo(CurrentRotation, TargetRotation, DeltaTime,
InterpSpeed);
48
49 Data.Actor->SetActorRotation(NewRotation);
50
51 return EStateTreeRunStatus::Running;
52}
TObjectPtr< AActor > Actor
Definition Task_SmoothTurnToTarget.h:16
float InterpSpeed
Definition Task_SmoothTurnToTarget.h:35