2class BotTurnToValidForward
extends BotStateBase
4 private int m_AngleCheck = 5;
5 private float m_TurnRate = 2;
7 private bool m_FoundDirection =
false;
8 private vector m_ValidDirection = vector.Zero;
9 private float m_TurnDirection = 1;
10 private float m_MinAngle = 500;
12 void BotTurnToValidForward(Bot bot = NULL, BotStateBase parent = NULL)
16 override void OnEntry (BotEventBase e)
19 m_ValidDirection =
m_Owner.GetDirection();
20 m_FoundDirection =
false;
25 g_Game.GetPlayer().GetInputInterface().SyncedRemoveOverride_ID(UAAimLeft);
26 g_Game.GetPlayer().GetInputInterface().SyncedRemoveOverride_ID(UAAimRight);
30 override void OnExit (BotEventBase e)
35 g_Game.GetPlayer().GetInputInterface().SyncedRemoveOverride_ID(UAAimLeft);
36 g_Game.GetPlayer().GetInputInterface().SyncedRemoveOverride_ID(UAAimRight);
40 BotEventBase GetNextEvent()
42 if (m_Bot.m_Target && m_Bot.m_Target.IsAlive())
43 return m_Bot.__Atkd__;
45 return m_Bot.__VaFw__;
50 if (!m_FoundDirection)
54 if (
GetGame().SurfaceIsSea(m_WaterPositionCheck[0], m_WaterPositionCheck[2]))
57 m_ValidDirection = -
m_Owner.GetDirection();
58 m_FoundDirection =
true;
62 const vector raycastHeight =
"0 0.75 0";
63 const float startPosOffset = 0.1;
64 const float raycastDist = 0.8;
65 const float raycastSphereRadius = 0.3;
68 vector hitPosition, hitNormal;
75 int rotationsAvailable = (360 / m_AngleCheck) / 2 + 1;
76 float lastResortTurnDirection = 0;
77 vector lastResortDirection = vector.Zero;
79 for (
int i = 1; i < rotationsAvailable; i++)
81 vector newLeftDirection = vector.RotateAroundZeroDeg(
m_Owner.GetDirection(), vector.Up, -m_AngleCheck * i);
82 vector newRightDirection = vector.RotateAroundZeroDeg(
m_Owner.GetDirection(), vector.Up, m_AngleCheck * i);
84 vector leftEndPos = startPos + newLeftDirection * 3;
85 vector rightEndPos = startPos + newRightDirection * 3;
88 bool resLeft = DayZPhysics.SphereCastBullet(startPos, leftEndPos, raycastSphereRadius, collisionMask,
m_Owner, hitObject, hitPosition, hitNormal,
hitFraction);
92 lastResortTurnDirection = -1;
93 lastResortDirection = newLeftDirection;
97 m_ValidDirection = vector.
RotateAroundZeroDeg(
m_Owner.GetDirection(), vector.Up, -(m_AngleCheck * (i - 1) + m_AngleCheck / 2));
99 m_FoundDirection =
true;
106 bool resRight = DayZPhysics.SphereCastBullet(startPos, rightEndPos, raycastSphereRadius, collisionMask,
m_Owner, hitObject, hitPosition, hitNormal,
hitFraction);
110 lastResortTurnDirection = 1;
111 lastResortDirection = newRightDirection;
112 if (rightStreak == 2)
116 m_FoundDirection =
true;
123 if (!m_FoundDirection)
125 m_TurnDirection = lastResortTurnDirection;
126 m_ValidDirection = lastResortDirection;
127 m_FoundDirection =
true;
133 if (!m_FoundDirection)
135 m_Bot.ProcessEvent(GetNextEvent());
139 float prod =
m_Owner.GetDirection().Length() * m_ValidDirection.
Length();
142 m_Bot.ProcessEvent(GetNextEvent());
146 float dot = vector.Dot(
m_Owner.GetDirection(), m_ValidDirection);
147 float angle = Math.Acos(dot / prod);
148 angle = Math.RAD2DEG * angle;
149 if (angle < 3 || angle > m_MinAngle + 0.5)
151 m_Bot.ProcessEvent(GetNextEvent());
155 m_MinAngle = Math.Min(angle, m_MinAngle);
159 slowDown = angle / 30;
161 slowDown = Math.Clamp(slowDown, 0.2, 1);
163 int inputID = UAAimLeft;
164 if (m_TurnDirection > 0)
165 inputID = UAAimRight;
168 g_Game.GetPlayer().GetInputInterface().SyncedOverride_ID(inputID, m_TurnDirection * m_TurnRate * slowDown, OverrideInputType.HOLD,
false);
HandStateEquipped OnEntry
enum ProcessDirectDamageFlags m_Owner
vector m_OwnerPosition
The owner performing the snap callback.
class WeaponChambering_Chamber_OnEntry extends WeaponChambering_Base OnExit
override void OnEntry(HandEventBase e)
override void OnExit(WeaponEventBase e)
proto native float Length()
Returns length of vector (magnitude)
static vector RotateAroundZeroDeg(vector vec, vector axis, float angle)
Rotate a vector around 0,0,0 by an angle in degrees.