adjust NPC dash direction

godot-4.3
John Montagu, the 4th Earl of Sandvich 2024-01-06 14:13:48 -08:00
parent 05ae280785
commit 58e46a3ae1
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
1 changed files with 13 additions and 6 deletions

View File

@ -61,16 +61,16 @@ public partial class DashDefensive : AttackState
// doc will still dash if you are farther than normal but // doc will still dash if you are farther than normal but
// moving towards him // moving towards him
float distThreshold = 50 - (dot * 20); float distThreshold = UseItemDistance - (dot * 20);
// dash towards if lance in anticipate state // dash towards if lance in anticipate state
// or just directly dash towards you if you are too far // or just directly dash towards you if you are too far
shouldDashTowards = (isTargetStunned || _dashedAway) && shouldDashTowards = (isTargetStunned || _dashedAway) &&
swordState is State.Weapon.SwordAnticipateState || (swordState is State.Weapon.SwordAnticipateState ||
dist > MaxDistanceToTarget; dist > MaxDistanceToTarget);
shouldDashAway = dist < distThreshold && !isTargetStunned && shouldDashAway = dist < distThreshold && !isTargetStunned &&
swordState is not State.Weapon.SwordAnticipateState; swordState is State.Weapon.SwordIdleState;
//if (!isTargetStunned && dist < 2500 && !_dashedAway) //if (!isTargetStunned && dist < 2500 && !_dashedAway)
if (shouldDashAway && !shouldDashTowards) if (shouldDashAway && !shouldDashTowards)
@ -83,9 +83,14 @@ public partial class DashDefensive : AttackState
} }
else if (shouldDashTowards && !shouldDashAway) else if (shouldDashTowards && !shouldDashAway)
{ {
// our required velocity is dependent on final distance to target
float maxVelocity = dist / 0.1f;
var dashSpeed = Mathf.Max(maxVelocity,
_originalDashModifier * NPC.Speed);
float ratio = dashSpeed / NPC.Speed;
_dashState.VelocityModifier = ratio;
// dash to player's predicted position // dash to player's predicted position
_dashState.VelocityModifier = _originalDashModifier * 1.75f;
var dashSpeed = _dashState.VelocityModifier * NPC.Speed;
var newPos = Utils.Physics.PredictNewPosition( var newPos = Utils.Physics.PredictNewPosition(
NPC.GlobalPosition, NPC.GlobalPosition,
dashSpeed, dashSpeed,
@ -100,6 +105,8 @@ public partial class DashDefensive : AttackState
NPC.UseCurrentItem(); NPC.UseCurrentItem();
} }
} }
return null;
} }
return PursueState ?? PassiveState; return PursueState ?? PassiveState;