From b4033d557ba5245680a7c3aa5f5c70aac1c38720 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Mon, 10 Jul 2023 05:20:20 +1000 Subject: [PATCH] NPC steering tweaks (#17911) - Slightly less twitchy in melee. - Resteer less. - More aggressive in pursuing running away targets. --- .../NPC/Components/NPCSteeringComponent.cs | 2 +- .../NPC/Systems/NPCCombatSystem.Melee.cs | 20 ++++++++++++++++--- .../NPC/Systems/NPCSteeringSystem.Context.cs | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Content.Server/NPC/Components/NPCSteeringComponent.cs b/Content.Server/NPC/Components/NPCSteeringComponent.cs index ed1eaa4a71..fef446cb60 100644 --- a/Content.Server/NPC/Components/NPCSteeringComponent.cs +++ b/Content.Server/NPC/Components/NPCSteeringComponent.cs @@ -48,7 +48,7 @@ public sealed class NPCSteeringComponent : Component [DataField("lastSteerDirection")] public Vector2 LastSteerDirection = Vector2.Zero; - public const int SteeringFrequency = 10; + public const int SteeringFrequency = 5; /// /// Last position we considered for being stuck. diff --git a/Content.Server/NPC/Systems/NPCCombatSystem.Melee.cs b/Content.Server/NPC/Systems/NPCCombatSystem.Melee.cs index 19abfb7467..558d7c5170 100644 --- a/Content.Server/NPC/Systems/NPCCombatSystem.Melee.cs +++ b/Content.Server/NPC/Systems/NPCCombatSystem.Melee.cs @@ -28,16 +28,30 @@ public sealed partial class NPCCombatSystem if (TryComp(component.Weapon, out var weapon)) { var cdRemaining = weapon.NextAttack - _timing.CurTime; + var attackCooldown = TimeSpan.FromSeconds(1f / _melee.GetAttackRate(component.Weapon, uid, weapon)); - // If CD remaining then backup. - if (cdRemaining < TimeSpan.FromSeconds(1f / _melee.GetAttackRate(component.Weapon, uid, weapon)) * 0.5f) + // Might as well get in range. + if (cdRemaining < attackCooldown * 0.45f) return; if (!_physics.TryGetNearestPoints(uid, component.Target, out var pointA, out var pointB)) return; - var idealDistance = weapon.Range * 1.5f; var obstacleDirection = pointB - args.WorldPosition; + + // If they're moving away then pursue anyway. + // If just hit then always back up a bit. + if (cdRemaining < attackCooldown * 0.90f && + TryComp(component.Target, out var targetPhysics) && + Vector2.Dot(targetPhysics.LinearVelocity, obstacleDirection) > 0f) + { + return; + } + + if (cdRemaining < TimeSpan.FromSeconds(1f / _melee.GetAttackRate(component.Weapon, uid, weapon)) * 0.45f) + return; + + var idealDistance = weapon.Range * 4f; var obstacleDistance = obstacleDirection.Length(); if (obstacleDistance > idealDistance || obstacleDistance == 0f) diff --git a/Content.Server/NPC/Systems/NPCSteeringSystem.Context.cs b/Content.Server/NPC/Systems/NPCSteeringSystem.Context.cs index cbe95be140..758a6ce481 100644 --- a/Content.Server/NPC/Systems/NPCSteeringSystem.Context.cs +++ b/Content.Server/NPC/Systems/NPCSteeringSystem.Context.cs @@ -382,7 +382,7 @@ public sealed partial class NPCSteeringSystem TransformComponent xform, float[] danger) { - var objectRadius = 0.15f; + var objectRadius = 0.10f; var detectionRadius = MathF.Max(0.35f, agentRadius + objectRadius); foreach (var ent in _lookup.GetEntitiesInRange(uid, detectionRadius, LookupFlags.Static))