51{
53 {
54 return *this;
55 }
56
57 const APlayerController* PC = GEngine->GetFirstLocalPlayerController(
World);
58
59 if (PC == nullptr || PC->PlayerCameraManager == nullptr)
60 {
61 return *this;
62 }
63
64 const FVector CameraLocation = PC->PlayerCameraManager->GetCameraLocation();
65 const FVector CameraForward = PC->PlayerCameraManager->GetCameraRotation().Vector();
66
68 float BestDot = -2.0f;
69 float BestDistSq = TNumericLimits<float>::Max();
70
72 {
73 if (Target->IsTargetValid() == false || Target->IsTargetable() == false)
74 {
75 continue;
76 }
77
78 const FVector ToTarget = Target->GetTargetedActorLocation() - CameraLocation;
79 const float DistSq = ToTarget.SizeSquared();
80
81 if (DistSq < KINDA_SMALL_NUMBER)
82 {
83 continue;
84 }
85
86 const FVector ToTargetDir = ToTarget / FMath::Sqrt(DistSq);
87 const float Dot = FVector::DotProduct(CameraForward, ToTargetDir);
88
89
90
91
92 if (FMath::IsNearlyEqual(Dot, BestDot, KINDA_SMALL_NUMBER) ? (DistSq < BestDistSq) : (Dot > BestDot))
93 {
94 Best = Target;
95 BestDot = Dot;
96 BestDistSq = DistSq;
97 }
98 }
99
101
102 if (Best)
103 {
105 }
106
107 return *this;
108}