Skip to content

Commit 5897069

Browse files
committed
basic Head validation so AI doesn't throw errors
1 parent 0503ca1 commit 5897069

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Data/Base.rte/AI/SharedBehaviors.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -864,28 +864,28 @@ function SharedBehaviors.GoToWpt(AI, Owner, Abort)
864864

865865
-- test jumping
866866
local JetAccel = Accel + Vector(-jetStrength, 0):RadRotate(Owner.RotAngle+1.375*math.pi+Owner:GetAimAngle(false)*0.25);
867-
local JumpPos = Owner.Head.Pos + PixelVel + JetAccel * (t*t*0.5);
867+
local JumpPos = (Owner.Head and Owner.Head.Pos or Owner.Pos) + PixelVel + JetAccel * (t*t*0.5);
868868

869869
-- a burst add a one time boost to acceleration
870870
if Owner.Jetpack:CanTriggerBurst() then
871871
JumpPos = JumpPos + Vector(-AI.jetBurstFactor, 0):AbsRotateTo(JetAccel);
872872
end
873873

874874
-- check for obstacles from the head
875-
Trace = SceneMan:ShortestDistance(Owner.Head.Pos, JumpPos, false);
876-
local jumpScore = SceneMan:CastObstacleRay(Owner.Head.Pos, Trace, JumpPos, Vector(), Owner.ID, Owner.IgnoresWhichTeam, rte.grassID, 3);
875+
Trace = SceneMan:ShortestDistance((Owner.Head and Owner.Head.Pos or Owner.Pos), JumpPos, false);
876+
local jumpScore = SceneMan:CastObstacleRay((Owner.Head and Owner.Head.Pos or Owner.Pos), Trace, JumpPos, Vector(), Owner.ID, Owner.IgnoresWhichTeam, rte.grassID, 3);
877877
if jumpScore < 0 then -- no obstacles: calculate the distance from the future pos to the wpt
878878
jumpScore = SceneMan:ShortestDistance(Waypoint.Pos, JumpPos, false).Magnitude;
879879
else -- the ray hit terrain or start inside terrain: avoid
880880
jumpScore = SceneMan:ShortestDistance(Waypoint.Pos, JumpPos, false).Largest * 2;
881881
end
882882

883883
-- test falling
884-
local FallPos = Owner.Head.Pos + PixelVel + Accel * (t*t*0.5);
884+
local FallPos = (Owner.Head and Owner.Head.Pos or Owner.Pos) + PixelVel + Accel * (t*t*0.5);
885885

886886
-- check for obstacles when falling/walking
887-
local Trace = SceneMan:ShortestDistance(Owner.Head.Pos, FallPos, false);
888-
SceneMan:CastObstacleRay(Owner.Head.Pos, Trace, FallPos, Vector(), Owner.ID, Owner.IgnoresWhichTeam, rte.grassID, 3);
887+
local Trace = SceneMan:ShortestDistance((Owner.Head and Owner.Head.Pos or Owner.Pos), FallPos, false);
888+
SceneMan:CastObstacleRay((Owner.Head and Owner.Head.Pos or Owner.Pos), Trace, FallPos, Vector(), Owner.ID, Owner.IgnoresWhichTeam, rte.grassID, 3);
889889

890890
if SceneMan:ShortestDistance(Waypoint.Pos, FallPos, false):MagnitudeIsLessThan(jumpScore) then
891891
AI.jump = false;

0 commit comments

Comments
 (0)