Match Jimmy controller arithmetic and facing to original probes

This commit is contained in:
UnixNight committed 2026-11-05 09:47:28 -05:00
1 parent 42ea2b8cd5
commit 0e2f426d42
60 files changed
+6027 -48

No files matched your search

+37 -27
View File
@@ -10,7 +10,7 @@ public enum PlayerPose { Idle, Run, Backpedal, Jump, Fall, Fly, Shoot, Swing }
/// <summary>
/// Walking, airborne steering and jetpack checkpoint. Recovered arithmetic is described in
/// movement-checkpoint.md. Legacy capsule, floor-derived pivot and60Hz are port policies;
/// jimmy-movement-stabilization.md. Legacy capsule, floor-derived pivot and60Hz are port policies;
/// original collision, intro, object interactions and animation timing remain open.
/// </summary>
public sealed class LabSimulation
@@ -32,6 +32,7 @@ public sealed class LabSimulation
private int movementMode;
private JetpackBurstState jumpState;
private bool forceFall;
private bool keyboardTurn, hasSupportPolygon;
private Vector3 noclipEntry;
private float noclipEntryYaw;
private int gadgetMode = -1;
@@ -189,6 +190,7 @@ public sealed class LabSimulation
Yaw = targetYaw = startYaw;
Speed = PublishedSpeed = TurnRate = extraAirAcceleration = shadowDistance = 0;
lateralContribution = 0; pendingImpulse = Vector3.Zero; movementMode = 0;
keyboardTurn=false;hasSupportPolygon=false;
jumpState = default;
forceFall = JetpackEffectVisible = false;
Shooting = false;
@@ -262,6 +264,7 @@ public sealed class LabSimulation
//424BE0..424C34 runs this wrapper before437940's ownership gate.
StepCeiling();
StepFloorPolicy(); //437940's base40E050, before the input-identity gate.
StepFacing(); //40E050→473240→43A420 also runs without input ownership.
if (controlled) StepPlayer(input);
Invisible.Step(FixedStepClock.Step, anyControlled ?? controlled, input.Fire, input.Jump,
Energy, IgnoresGadgetEnergy, AdjustEnergy);
@@ -444,26 +447,26 @@ public sealed class LabSimulation
//438A60 dispatches by stored movement mode, not current support.
if (movementMode == 0)
{
if (TracksBubbleOrientation && (input.Forward || input.Left || input.Right
|| input.Backward && !(GadgetMode is -1 or 3 && input.Fire))) targetPitch=targetRoll=0;
float yawDelta = 0;
if (input.Left) { yawDelta += 20; lateralContribution = -1000; Speed = RecoveredMotion.AddSpeed(Speed,MaximumSpeed); }
else if (input.Right) { yawDelta -= 20; lateralContribution = 1000; Speed = RecoveredMotion.AddSpeed(Speed,MaximumSpeed); }
if (input.Forward) { yawDelta *= 0.5f; Speed = RecoveredMotion.AddSpeed(Speed,MaximumSpeed); }
if (yawDelta != 0) targetYaw = Yaw + yawDelta;
if (input.Backward) Speed = MathF.Max(Speed - 52.5f, -300);
else if (!input.Forward) Speed = RecoveredMotion.ReleaseSpeed(Speed);
//The830 backward clock owner remains unresolved; ordinary state0
//does not invent a hold timer or admit its seeded auto-turn branch.
var ground=JimmyGroundMotion.Input(new(Speed,targetYaw),Yaw,input,MaximumSpeed,
blockBackward:(GadgetMode is -1 or 3)&&input.Fire);
Speed=ground.State.Speed;targetYaw=ground.State.TargetYaw;lateralContribution=ground.Lateral;
if(input.Left||input.Right)keyboardTurn=true;
if(ground.HeadingUpdated)targetPitch=targetRoll=0;
}
else if (movementMode==2)
{
var steering=BubbleMotion.StepInput(Speed,TurnRate,input,Grounded,dt,MaximumSpeed);
Speed=steering.Speed; TurnRate=steering.TurnRate;
if(input.Left||input.Right)keyboardTurn=true;
targetPitch=steering.TargetPitch; targetRoll=steering.TargetRoll; targetYaw=Yaw;
}
else
{
var steering = AirSteering.Step(Speed, TurnRate, input, dt,MaximumSpeed);
var steering = JimmyAirMotion.Input(new(Speed,TurnRate,keyboardTurn),input,Grounded,dt,MaximumSpeed);
Speed = steering.Speed; TurnRate = steering.TurnRate;
keyboardTurn=steering.KeyboardTurn;
if (TracksBubbleOrientation) { targetPitch=0; targetRoll=-TurnRate; }
//439E2B preserves current yaw as the destination; air apply then
//438011..43802B adds the independent turn rate directly to yaw.
@@ -492,15 +495,16 @@ public sealed class LabSimulation
StopForPrimaryFire,SetShooting,AdjustEnergy);
}
private void StepFacing()
{
var rotation=JimmyOrientation.Step(new(Pitch,Yaw,Roll),new(targetPitch,targetYaw,targetRoll),FixedStepClock.Step);
Pitch=rotation.X;Yaw=rotation.Y;Roll=rotation.Z;
}
private void StepPlayer(PlayerInput input)
{
ControllerSteps++;
const float dt = FixedStepClock.Step;
if (TracksBubbleOrientation)
{
Pitch+=(targetPitch-Pitch)*dt*4.5f;
Roll+=(targetRoll-Roll)*dt*4.5f;
}
if (movementMode==2)
{
var bubble=BubbleMotion.StepApply(Speed,TurnRate,Yaw,Pitch,Velocity,Grounded,input.Jump,dt);
@@ -508,8 +512,6 @@ public sealed class LabSimulation
if (Grounded) { BubbleBounces++; if (bubble.Boing) GadgetSound?.Invoke(106,false); }
return;
}
var yawError = MathF.IEEERemainder(targetYaw - Yaw, 360);
Yaw = (Yaw + yawError * dt * 3.7f) % 360;
//437A96 selects air mode on held jump;437B9E..BAC resets jump/mode/turn
//only in the player's grounded/released update, after input when fresh.
if (input.Jump) movementMode = 1;
@@ -517,15 +519,18 @@ public sealed class LabSimulation
{
movementMode = 0; TurnRate = 0;
}
if (Velocity.LengthSquared() != 0 || movementMode == 0 && lateralContribution != 0)
Yaw = (Yaw + TurnRate * dt) % 360;
var (sin, cos) = Trig(Yaw);
var velocity = new Vector3(-sin * Speed, Velocity.Y, cos * Speed);
//437CDx ground uses /45 then dt;43803B air uses /55 without dt.
const float friction = .8f;
var sideSpeed = movementMode == 0 ? (TurnRate * (1 - friction) * Speed / 45 + lateralContribution) * dt
: TurnRate * (1 - friction) * Speed * .0181818176060915f;
velocity += new Vector3(cos, 0, sin) * sideSpeed;
Vector3 velocity;
if(movementMode==0)
{
var ground=JimmyGroundMotion.Apply(Speed,Velocity,new(Pitch,Yaw,Roll),TurnRate,
lateralContribution,Grounded,hasSupportPolygon,dt);
velocity=ground.Velocity;Pitch=ground.Rotation.X;Yaw=ground.Rotation.Y;Roll=ground.Rotation.Z;
}
else
{
var airMotion=JimmyAirMotion.Apply(Speed,TurnRate,new(Pitch,Yaw,Roll),Velocity,dt);
velocity=airMotion.Velocity;Pitch=airMotion.Rotation.X;Yaw=airMotion.Rotation.Y;Roll=airMotion.Rotation.Z;
}
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,
@@ -576,6 +581,10 @@ public sealed class LabSimulation
}
}
Grounded = result.Grounded && velocity.Y <= 0;
//The capsule has no original338 support polygon. Combining source
//downward pressure with its slide solver blocks the lab stair route.
//Keep that solver's baseline until the source body/contact bridge lands.
hasSupportPolygon=false;
if (Grounded && velocity.Y < 0 || result.HitCeiling && velocity.Y > 0 && ceilingRay == null) velocity.Y = 0;
if (Grounded) { extraAirAcceleration = 0; forceFall = false; }
Velocity = velocity;
@@ -598,6 +607,7 @@ public sealed class LabSimulation
pendingImpulse = result.Body.Impulse;
extraAirAcceleration = result.Body.Acceleration.Y;
Grounded = result.Body.Supported;
hasSupportPolygon=result.SupportHit!=null;
if (Grounded) forceFall = false;
if (result.Landing != null) Landings++;
if (result.Contact is { StoredNormal.Y: > -.7f }) {WallHits++;Grappler?.Contact();}