More NPC steering fixes (#17042)

This commit is contained in:
metalgearsloth
2023-06-02 00:28:23 +10:00
committed by GitHub
parent d1de9b1f40
commit 5b1af38277
2 changed files with 59 additions and 27 deletions

View File

@@ -348,6 +348,17 @@ public sealed partial class NPCSteeringSystem : SharedNPCSteeringSystem
}
DebugTools.Assert(!float.IsNaN(interest[0]));
// Don't steer too frequently to avoid twitchiness.
// This should also implicitly solve tie situations.
// I think doing this after all the ops above is best?
// Originally I had it way above but sometimes mobs would overshoot their tile targets.
if (!forceSteer && steering.NextSteer > curTime)
{
SetDirection(mover, steering, steering.LastSteerDirection, false);
return;
}
// Avoid static objects like walls
CollisionAvoidance(uid, offsetRot, worldPos, agentRadius, layer, mask, xform, danger, dangerPoints, bodyQuery, xformQuery);
DebugTools.Assert(!float.IsNaN(danger[0]));
@@ -376,17 +387,6 @@ public sealed partial class NPCSteeringSystem : SharedNPCSteeringSystem
resultDirection = new Angle(desiredDirection * InterestRadians).ToVec();
}
// Don't steer too frequently to avoid twitchiness.
// This should also implicitly solve tie situations.
// I think doing this after all the ops above is best?
// Originally I had it way above but sometimes mobs would overshoot their tile targets.
if (!forceSteer && steering.NextSteer > curTime)
{
SetDirection(mover, steering, steering.LastSteerDirection, false);
return;
}
steering.NextSteer = curTime + TimeSpan.FromSeconds(1f / NPCSteeringComponent.SteeringFrequency);
steering.LastSteerDirection = resultDirection;
DebugTools.Assert(!float.IsNaN(resultDirection.X));