Restore original airborne steering for jumps and jetpack bursts
This commit is contained in:
1 parent
b58138d7ba
commit
976e677019
16 files changed
+357
-54
No files matched your search
@@ -0,0 +1,36 @@
|
||||
namespace GamePort.Game;
|
||||
|
||||
public readonly record struct AirSteeringResult(float Speed, float TurnRate);
|
||||
|
||||
/// <summary>Keyboard subset of normal airborne input439900 (mode1).
|
||||
/// Modes1/2 share the handler; special flight mode2 and mouse/analog are separate.
|
||||
/// </summary>
|
||||
public static class AirSteering
|
||||
{
|
||||
public const float TurnAcceleration = 100; //48D96C, applied with dt.
|
||||
public const float TurnLimit = 30; //439D81..439DB7, ordinary mode1.
|
||||
public const float CoastThreshold = 0.9090909361839294f; //49D5DC.
|
||||
|
||||
public static AirSteeringResult Step(float speed, float turnRate, PlayerInput input, float seconds)
|
||||
{
|
||||
if (!float.IsFinite(speed) || !float.IsFinite(turnRate) || !float.IsFinite(seconds) || seconds < 0 || seconds >= 1)
|
||||
throw new ArgumentOutOfRangeException(nameof(seconds));
|
||||
var turnStep = TurnAcceleration * seconds;
|
||||
if (input.Left) turnRate += turnStep;
|
||||
else if (input.Right) turnRate -= turnStep;
|
||||
else if (turnRate < 0) turnRate = MathF.Min(0, turnRate + turnStep);
|
||||
else if (turnRate > 0) turnRate = MathF.Max(0, turnRate - turnStep);
|
||||
turnRate = Math.Clamp(turnRate, -TurnLimit, TurnLimit);
|
||||
|
||||
if (input.Forward) speed = RecoveredMotion.AddSpeed(speed);
|
||||
else if (speed > RecoveredMotion.MaximumSpeed * CoastThreshold)
|
||||
speed -= RecoveredMotion.SpeedDecay * .5f;
|
||||
//439C1D..439CB2 brakes to0, without starting reverse flight.
|
||||
if (input.Backward)
|
||||
{
|
||||
if (speed > 0) speed = MathF.Max(0, speed - RecoveredMotion.SpeedDecay * .5f);
|
||||
else if (speed < 0) speed = MathF.Min(0, speed + RecoveredMotion.SpeedDecay);
|
||||
}
|
||||
return new(speed, turnRate);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user