Ignore non-hard bodies for npc steering (#12990)

This commit is contained in:
metalgearsloth
2022-12-12 21:20:13 +11:00
committed by GitHub
parent bbfa8b5ae6
commit 666d81a869
3 changed files with 16 additions and 13 deletions

View File

@@ -39,7 +39,7 @@ public sealed partial class NPCCombatSystem
var obstacleDirection = pointB - args.WorldPosition;
var obstacleDistance = obstacleDirection.Length;
if (obstacleDistance > idealDistance)
if (obstacleDistance > idealDistance || obstacleDistance == 0f)
{
// Don't want to get too far.
return;

View File

@@ -306,7 +306,8 @@ public sealed partial class NPCSteeringSystem
Vector2 worldPos,
float agentRadius,
float moveSpeed,
PhysicsComponent body,
int layer,
int mask,
TransformComponent xform,
float[] danger,
List<Vector2> dangerPoints,
@@ -322,8 +323,8 @@ public sealed partial class NPCSteeringSystem
!bodyQuery.TryGetComponent(ent, out var otherBody) ||
!otherBody.Hard ||
!otherBody.CanCollide ||
((body.CollisionMask & otherBody.CollisionLayer) == 0x0 &&
(body.CollisionLayer & otherBody.CollisionMask) == 0x0))
(mask & otherBody.CollisionLayer) == 0x0 &&
(layer & otherBody.CollisionMask) == 0x0)
{
continue;
}
@@ -331,10 +332,10 @@ 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 - worldPos;
var obstableDistance = obstacleDirection.Length;
if (obstableDistance > detectionRadius)
if (obstableDistance > detectionRadius || obstableDistance == 0f)
continue;
dangerPoints.Add(pointB);
@@ -363,9 +364,10 @@ public sealed partial class NPCSteeringSystem
Angle offsetRot,
Vector2 worldPos,
float agentRadius,
int layer,
int mask,
PhysicsComponent body,
TransformComponent xform,
float[] interest,
float[] danger,
EntityQuery<PhysicsComponent> bodyQuery,
EntityQuery<TransformComponent> xformQuery)
@@ -382,8 +384,8 @@ public sealed partial class NPCSteeringSystem
!bodyQuery.TryGetComponent(ent, out var otherBody) ||
!otherBody.Hard ||
!otherBody.CanCollide ||
(body.CollisionMask & otherBody.CollisionLayer) == 0x0 &&
(body.CollisionLayer & otherBody.CollisionMask) == 0x0 ||
(mask & otherBody.CollisionLayer) == 0x0 &&
(layer & otherBody.CollisionMask) == 0x0 ||
!factionQuery.TryGetComponent(ent, out var otherFaction) ||
!_faction.IsFriendly(uid, ent, ourFaction, otherFaction) ||
Vector2.Dot(otherBody.LinearVelocity, ourVelocity) < 0f)
@@ -398,10 +400,10 @@ public sealed partial class NPCSteeringSystem
continue;
}
var obstacleDirection = (pointB - worldPos);
var obstacleDirection = pointB - worldPos;
var obstableDistance = obstacleDirection.Length;
if (obstableDistance > detectionRadius)
if (obstableDistance > detectionRadius || obstableDistance == 0f)
continue;
obstacleDirection = offsetRot.RotateVec(obstacleDirection);

View File

@@ -299,6 +299,7 @@ namespace Content.Server.NPC.Systems
var danger = steering.Danger;
var agentRadius = steering.Radius;
var worldPos = xform.WorldPosition;
var (layer, mask) = _physics.GetHardCollision(uid);
// Use rotation relative to parent to rotate our context vectors by.
var offsetRot = -_mover.GetParentGridAngle(mover);
@@ -326,10 +327,10 @@ namespace Content.Server.NPC.Systems
DebugTools.Assert(!float.IsNaN(interest[0]));
// Avoid static objects like walls
CollisionAvoidance(uid, offsetRot, worldPos, agentRadius, tickMove, body, xform, danger, dangerPoints, bodyQuery, xformQuery);
CollisionAvoidance(uid, offsetRot, worldPos, agentRadius, tickMove, layer, mask, xform, danger, dangerPoints, bodyQuery, xformQuery);
DebugTools.Assert(!float.IsNaN(danger[0]));
Separation(uid, offsetRot, worldPos, agentRadius, body, xform, interest, danger, bodyQuery, xformQuery);
Separation(uid, offsetRot, worldPos, agentRadius, layer, mask, body, xform, danger, bodyQuery, xformQuery);
// Remove the danger map from the interest map.
var desiredDirection = -1;