From e9a4b1c747ede7f34adee1c75b49cff38a96e1f2 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Mon, 4 Sep 2023 14:34:20 +1000 Subject: [PATCH] Fix NPC juke stuttering (#19805) --- Content.Server/NPC/Systems/NPCJukeSystem.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Content.Server/NPC/Systems/NPCJukeSystem.cs b/Content.Server/NPC/Systems/NPCJukeSystem.cs index 1f089a666c..19f566405a 100644 --- a/Content.Server/NPC/Systems/NPCJukeSystem.cs +++ b/Content.Server/NPC/Systems/NPCJukeSystem.cs @@ -20,7 +20,7 @@ public sealed class NPCJukeSystem : EntitySystem [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly EntityLookupSystem _lookup = default!; [Dependency] private readonly MeleeWeaponSystem _melee = default!; - [Dependency] private readonly SharedPhysicsSystem _physics = default!; + [Dependency] private readonly SharedTransformSystem _transform = default!; private EntityQuery _npcMeleeQuery; private EntityQuery _npcRangedQuery; @@ -156,15 +156,19 @@ public sealed class NPCJukeSystem : EntitySystem if (cdRemaining < attackCooldown * 0.45f) return; - if (!_physics.TryGetNearestPoints(uid, melee.Target, out var pointA, out var pointB)) - return; + // If we get whacky boss mobs might need nearestpos that's more of a PITA + // so will just use this for now. + var obstacleDirection = _transform.GetWorldPosition(melee.Target) - args.WorldPosition; - var obstacleDirection = pointB - args.WorldPosition; + if (obstacleDirection == Vector2.Zero) + { + obstacleDirection = _random.NextVector2(); + } // If they're moving away then pursue anyway. // If just hit then always back up a bit. if (cdRemaining < attackCooldown * 0.90f && - TryComp(melee.Target, out var targetPhysics) && + _physicsQuery.TryGetComponent(melee.Target, out var targetPhysics) && Vector2.Dot(targetPhysics.LinearVelocity, obstacleDirection) > 0f) { return; @@ -173,6 +177,7 @@ public sealed class NPCJukeSystem : EntitySystem if (cdRemaining < TimeSpan.FromSeconds(1f / _melee.GetAttackRate(weaponUid, uid, weapon)) * 0.45f) return; + // TODO: Probably add in our bounds and target bounds for ideal distance. var idealDistance = weapon.Range * 4f; var obstacleDistance = obstacleDirection.Length();