11{
13
14 if (Data.EnemyActor == nullptr || Data.TargetActor == nullptr)
15 {
16 return EStateTreeRunStatus::Failed;
17 }
18
19 FVector MonsterLoc = Data.
EnemyActor->GetActorLocation();
20 FVector PlayerLoc = Data.TargetActor->GetActorLocation();
21 FVector RetreatDirection = (MonsterLoc - PlayerLoc).GetSafeNormal2D();
22 FVector IdealDestination = MonsterLoc + (RetreatDirection * Data.RetreatDistance);
23
24 UNavigationSystemV1* NavSys = UNavigationSystemV1::GetCurrent(Data.EnemyActor->GetWorld());
25 if (NavSys)
26 {
27 FVector HitLocation;
28
29 bool bBlocked = NavSys->NavigationRaycast(Data.EnemyActor, MonsterLoc, IdealDestination, HitLocation);
30
31 if (bBlocked)
32 {
33 Data.OutDestination = HitLocation - (RetreatDirection * 50.0f);
34 }
35 else
36 {
37 Data.OutDestination = IdealDestination;
38 }
39 }
40 else
41 {
42
43 Data.OutDestination = IdealDestination;
44 }
45
46 return EStateTreeRunStatus::Succeeded;
47}
TObjectPtr< AActor > EnemyActor
Definition Task_Retreat.h:16
FTask_Retreat_Data FInstanceDataType
Definition Task_Retreat.h:32