Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIDecoTestIsMovingTowardsMe.c
Go to the documentation of this file.
1 /*
2 Returns true when velocity vector is aimed towards me (angle is below 90 degrees).
3 */
4 class SCR_AIDecoTestIsMovingTowardsMe : DecoratorTestScripted
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 };
SCR_AIDecoTestIsMovingTowardsMe
Definition: SCR_AIDecoTestIsMovingTowardsMe.c:4