NPC steering tweaks (#17911)
- Slightly less twitchy in melee. - Resteer less. - More aggressive in pursuing running away targets.
This commit is contained in:
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Last position we considered for being stuck.
|
||||
|
||||
@@ -28,16 +28,30 @@ public sealed partial class NPCCombatSystem
|
||||
if (TryComp<MeleeWeaponComponent>(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<PhysicsComponent>(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)
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user