NPC steering tweaks (#17911)
- Slightly less twitchy in melee. - Resteer less. - More aggressive in pursuing running away targets.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user