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")]
|
[DataField("lastSteerDirection")]
|
||||||
public Vector2 LastSteerDirection = Vector2.Zero;
|
public Vector2 LastSteerDirection = Vector2.Zero;
|
||||||
|
|
||||||
public const int SteeringFrequency = 10;
|
public const int SteeringFrequency = 5;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Last position we considered for being stuck.
|
/// Last position we considered for being stuck.
|
||||||
|
|||||||
@@ -28,16 +28,30 @@ public sealed partial class NPCCombatSystem
|
|||||||
if (TryComp<MeleeWeaponComponent>(component.Weapon, out var weapon))
|
if (TryComp<MeleeWeaponComponent>(component.Weapon, out var weapon))
|
||||||
{
|
{
|
||||||
var cdRemaining = weapon.NextAttack - _timing.CurTime;
|
var cdRemaining = weapon.NextAttack - _timing.CurTime;
|
||||||
|
var attackCooldown = TimeSpan.FromSeconds(1f / _melee.GetAttackRate(component.Weapon, uid, weapon));
|
||||||
|
|
||||||
// If CD remaining then backup.
|
// Might as well get in range.
|
||||||
if (cdRemaining < TimeSpan.FromSeconds(1f / _melee.GetAttackRate(component.Weapon, uid, weapon)) * 0.5f)
|
if (cdRemaining < attackCooldown * 0.45f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!_physics.TryGetNearestPoints(uid, component.Target, out var pointA, out var pointB))
|
if (!_physics.TryGetNearestPoints(uid, component.Target, out var pointA, out var pointB))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var idealDistance = weapon.Range * 1.5f;
|
|
||||||
var obstacleDirection = pointB - args.WorldPosition;
|
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();
|
var obstacleDistance = obstacleDirection.Length();
|
||||||
|
|
||||||
if (obstacleDistance > idealDistance || obstacleDistance == 0f)
|
if (obstacleDistance > idealDistance || obstacleDistance == 0f)
|
||||||
|
|||||||
@@ -382,7 +382,7 @@ public sealed partial class NPCSteeringSystem
|
|||||||
TransformComponent xform,
|
TransformComponent xform,
|
||||||
float[] danger)
|
float[] danger)
|
||||||
{
|
{
|
||||||
var objectRadius = 0.15f;
|
var objectRadius = 0.10f;
|
||||||
var detectionRadius = MathF.Max(0.35f, agentRadius + objectRadius);
|
var detectionRadius = MathF.Max(0.35f, agentRadius + objectRadius);
|
||||||
|
|
||||||
foreach (var ent in _lookup.GetEntitiesInRange(uid, detectionRadius, LookupFlags.Static))
|
foreach (var ent in _lookup.GetEntitiesInRange(uid, detectionRadius, LookupFlags.Static))
|
||||||
|
|||||||
Reference in New Issue
Block a user