Restore original airborne steering for jumps and jetpack bursts

This commit is contained in:
UnixNight committed 2026-10-24 20:57:39 -04:00
1 parent b58138d7ba
commit 976e677019
16 files changed
+357 -54

No files matched your search

+36
View File
@@ -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);
}
}
+21 -3
View File
@@ -7,7 +7,7 @@ public readonly record struct PlayerInput(bool Forward, bool Backward, bool Left
public enum PlayerPose { Idle, Run, Backpedal, Jump, Fall, Fly }
/// <summary>
/// No-gadget walking checkpoint. Recovered input/arithmetic is described in
/// Walking, airborne steering and jetpack checkpoint. Recovered arithmetic is described in
/// movement-checkpoint.md. Capsule, floor-derived pivot and 60Hz are port policies;
/// original collision, intro, object interactions and animation timing remain open.
/// </summary>
@@ -33,6 +33,7 @@ public sealed class LabSimulation
public Vector3 Velocity { get; private set; }
public float Yaw { get; private set; }
public float Speed { get; private set; }
public float TurnRate { get; private set; }
public bool Grounded { get; private set; }
public PlayerPose Pose => Grounded ? Speed < -1 ? PlayerPose.Backpedal : Speed > 1 ? PlayerPose.Run : PlayerPose.Idle
: jumpState.JumpState == 3 && jumpState.EffectRemaining > 0 ? PlayerPose.Fly
@@ -74,7 +75,7 @@ public sealed class LabSimulation
Position = new(sourceStart.X, floor + SceneCollision.Skin, sourceStart.Z);
Velocity = Vector3.Zero;
Yaw = targetYaw = startYaw;
Speed = extraAirAcceleration = shadowDistance = 0;
Speed = TurnRate = extraAirAcceleration = shadowDistance = 0;
jumpState = default;
forceFall = JetpackEffectVisible = false;
InteractionRadius = 60; Bursts = 0;
@@ -109,11 +110,25 @@ public sealed class LabSimulation
if (input.Backward) Speed = MathF.Max(Speed - 52.5f, -300);
else if (!input.Forward) Speed = RecoveredMotion.ReleaseSpeed(Speed);
}
else
{
var steering = AirSteering.Step(Speed, TurnRate, input, dt);
Speed = steering.Speed; TurnRate = steering.TurnRate;
//439E2B preserves current yaw as the destination; air apply then
//438011..43802B adds the independent turn rate directly to yaw.
targetYaw = Yaw;
}
var yawError = MathF.IEEERemainder(targetYaw - Yaw, 360);
Yaw = (Yaw + yawError * dt * 3.7f) % 360;
if (Velocity.LengthSquared() != 0 || Grounded && lateral != 0)
Yaw = (Yaw + TurnRate * dt) % 360;
var (sin, cos) = Trig(Yaw);
var velocity = new Vector3(-sin * Speed, Velocity.Y, cos * Speed);
if (Grounded) velocity += new Vector3(cos, 0, sin) * (lateral * dt);
//437CDx ground uses /45 then dt;43803B air uses /55 without dt.
const float friction = .8f;
var sideSpeed = Grounded ? (TurnRate * (1 - friction) * Speed / 45 + lateral) * dt
: TurnRate * (1 - friction) * Speed * .0181818176060915f;
velocity += new Vector3(cos, 0, sin) * sideSpeed;
if (collision.GroundHeight(ActorRoot, 2500) is { } shadowFloor)
shadowDistance = MathF.Abs(ActorRoot.Y - shadowFloor - 13);
var air = JetpackBurst.Step(jumpState, new(Grounded, input.Jump, velocity.Y, shadowDistance,
@@ -170,6 +185,9 @@ public sealed class LabSimulation
public static PlayerInput SmokeInput(int step) => new(step < 120, false, false,
step >= 120 && step < 180, step >= 72 && step < 84);
public static PlayerInput JetpackSmokeInput(int step) => new(step is >= 45 and < 80,
step is >= 80 and < 120, step is >= 60 and < 95, false, step < 180);
public bool SmokePassed => Steps >= 240 && Travel > 50 && MaximumRise > 20 && Jumps > 0 && Landings > 0 && Grounded;
public string Report => $"Walk checkpoint: steps={Steps}, travel={Travel:F2}, jumps={Jumps}, landings={Landings}, max rise={MaximumRise:F2}, wall hits={WallHits}, grounded={Grounded}, feet={Position}.";
}