Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIGetCarAvoidPosition.c
Go to the documentation of this file.
1 /*
2 Returns position for a character to avoid a vehicle.
3 The position is on the left or ride side of vehicle direction, depending on which side the character is.
4 */
5 class SCR_AIGetCarAvoidPosition : AITaskScripted
6 {
7  [Attribute("1", UIWidgets.EditBox)]
8  protected float m_fAsideMoveDistance;
9 
10  protected static const string VEHICLE_PORT = "Vehicle";
11  protected static const string POSITION_PORT = "Position";
12 
13  override bool VisibleInPalette() { return true; }
14 
15  override string GetOnHoverDescription()
16  {
17  return "Returns position for a character to avoid a vehicle.";
18  }
19 
20  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
21  {
22  IEntity myEntity = owner.GetControlledEntity();
23 
24  IEntity vehicle;
25  GetVariableIn(VEHICLE_PORT, vehicle);
26  if (!vehicle || !myEntity)
27  return ENodeResult.FAIL;
28 
29  // Get my pos in vehicle space
30  vector myPos = myEntity.GetOrigin();
31  vector myPosVehicleSpace = vehicle.CoordToLocal(myPos);
32 
33  // Vehicle's aside vector, Y component removed
34  vector vehicleAside = vehicle.GetTransformAxis(0);
35  vehicleAside[1] = 0;
36  if (vehicleAside.LengthSq() < 0.01)
37  {
38  // If vehicle aside vector is not in XZ plane, probably vehicle is flipped sideways
39  // In this case let's move away from vehicle
40 
41  vector vectorAwayFromVehicle = vector.Direction(vehicle.GetOrigin(), myPos);
42  vectorAwayFromVehicle.Normalize();
43 
44  vector posOut = myPos + m_fAsideMoveDistance * vectorAwayFromVehicle;
45  SetVariableOut(POSITION_PORT, posOut);
46  }
47  else
48  {
49  vehicleAside.Normalize();
50  // Decide which direction we should move
51  vector myOffsetDirection = vehicleAside; // Direction where we will move
52  if (myPosVehicleSpace[0] < 0) // I am left of vehicle
53  myOffsetDirection = -myOffsetDirection;
54 
55  vector posOut = myPos + m_fAsideMoveDistance * myOffsetDirection;
56 
57  SetVariableOut(POSITION_PORT, posOut);
58  }
59 
60  return ENodeResult.SUCCESS;
61  }
62 
63  protected static ref TStringArray s_aVarsIn = { VEHICLE_PORT };
64  override TStringArray GetVariablesIn() { return s_aVarsIn; }
65 
66  protected static ref TStringArray s_aVarsOut = { POSITION_PORT };
67  override TStringArray GetVariablesOut() { return s_aVarsOut; }
68 }
s_aVarsOut
SCR_AIPickupInventoryItemsBehavior s_aVarsOut
Definition: SCR_AIGetCombatMoveRequestParameters.c:149
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_AIGetCarAvoidPosition
Definition: SCR_AIGetCarAvoidPosition.c:5