Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIGetCarAvoidPosition.c
Go to the documentation of this file.
1/*
2Returns position for a character to avoid a vehicle.
3The position is on the left or ride side of vehicle direction, depending on which side the character is.
4*/
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 static override bool VisibleInPalette() { return true; }
14
15 static 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;
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;
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
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 };
68}
proto external vector GetOrigin()
proto external vector GetTransformAxis(int axis)
See IEntity::GetTransformAxis.
proto external vector CoordToLocal(vector coord)
proto void SetVariableOut(string name, void val)
proto bool GetVariableIn(string name, out void val)
override TStringArray GetVariablesIn()
override TStringArray GetVariablesOut()
static ref TStringArray s_aVarsOut
static ref TStringArray s_aVarsIn
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
static override bool VisibleInPalette()
static override string GetOnHoverDescription()
ENodeResult
Definition ENodeResult.c:13
SCR_FieldOfViewSettings Attribute
array< string > TStringArray
Definition Types.c:385