Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIDecoTestIsMovingTowardsMe.c
Go to the documentation of this file.
1/*
2Returns true when velocity vector is aimed towards me (angle is below 90 degrees).
3*/
5{
6 protected override bool TestFunction(AIAgent agent, IEntity controlled)
7 {
8 if (!controlled)
9 return false;
10
11 Physics phy = controlled.GetPhysics();
12
13 if (!phy)
14 return false;
15
16 // Bail if velocity is around zero
17 vector velocityWorld = phy.GetVelocity();
18 float velocityAbsSq = velocityWorld.LengthSq();
19 if (velocityAbsSq <= 0.001)
20 return false;
21
22 vector velocityDir = velocityWorld.Normalized();
23
24 IEntity myEntity = agent.GetControlledEntity();
25 if (!myEntity)
26 return false;
27
28 vector vecToMe = vector.Direction(controlled.GetOrigin(), myEntity.GetOrigin());
29 vecToMe.Normalize();
30
31 float cosAngle = vector.Dot(vecToMe, velocityDir);
32
33 return cosAngle > 0;
34 }
35};
proto external vector GetOrigin()
proto external Physics GetPhysics()
override bool TestFunction(AIAgent agent, IEntity controlled)