More NPC steering tweaks (#14119)

This commit is contained in:
metalgearsloth
2023-02-15 16:54:06 +11:00
committed by GitHub
parent 781ec8e9eb
commit 99dfe5694a
5 changed files with 49 additions and 12 deletions

View File

@@ -320,7 +320,7 @@ public sealed partial class NPCSteeringSystem
EntityQuery<PhysicsComponent> bodyQuery,
EntityQuery<TransformComponent> xformQuery)
{
var detectionRadius = MathF.Max(1.5f, agentRadius + moveSpeed / 4f);
var detectionRadius = MathF.Max(1.5f, agentRadius);
foreach (var ent in _lookup.GetEntitiesInRange(uid, detectionRadius, LookupFlags.Static))
{
@@ -338,12 +338,24 @@ public sealed partial class NPCSteeringSystem
if (!_physics.TryGetNearestPoints(uid, ent, out var pointA, out var pointB, xform, xformQuery.GetComponent(ent)))
continue;
var obstacleDirection = pointB - worldPos;
var obstacleDirection = pointB - pointA;
var obstableDistance = obstacleDirection.Length;
if (obstableDistance > detectionRadius || obstableDistance == 0f)
if (obstableDistance > detectionRadius)
continue;
// Fallback to worldpos if we're colliding.
if (obstableDistance == 0f)
{
obstacleDirection = pointB - worldPos;
obstableDistance = obstacleDirection.Length;
if (obstableDistance == 0f)
continue;
obstableDistance = agentRadius;
}
dangerPoints.Add(pointB);
obstacleDirection = offsetRot.RotateVec(obstacleDirection);
var norm = obstacleDirection.Normalized;