using System.Numerics; using GamePort.Assets; namespace GamePort.Game; public readonly record struct PlayerInput(bool Forward, bool Backward, bool Left, bool Right, bool Jump, bool Rise = false, bool Descend = false, bool StrafeLeft = false, bool StrafeRight = false, bool Fast = false, bool Fire = false); public enum PlayerPose { Idle, Run, Backpedal, Jump, Fall, Fly, Shoot } /// /// Walking, airborne steering and jetpack checkpoint. Recovered arithmetic is described in /// movement-checkpoint.md. Legacy capsule, floor-derived pivot and60Hz are port policies; /// original collision, intro, object interactions and animation timing remain open. /// public sealed class LabSimulation { public const float BodyRadius = 24; // Provisional, not a recovered collider dimension. private readonly SceneCollision collision; private readonly Func? cameraRay; private readonly Func? ceilingRay; private readonly OriginalBodyPhysics? originalBody; private readonly PlayerEnergy energy; private readonly Vector3 sourceStart; private readonly float startYaw, modelMinimumY, rootHeight, startFloor; private float targetYaw, extraAirAcceleration, shadowDistance, lateralContribution; private float targetPitch, targetRoll; private int? retainedSupportMaterial; private bool bubbleLoop; private PlayerPose bubblePose; private Vector3 pendingImpulse; private int movementMode; private JetpackBurstState jumpState; private bool forceFall; private Vector3 noclipEntry; private float noclipEntryYaw; private int gadgetMode = -1; public bool Noclip { get; private set; } public bool HasNoclipEntry { get; private set; } public float NoclipSpeed { get; set; } = 600; public Func? JetpackInventoryState { get; set; } public string LevelCode { get; set; } = "LV1B"; public InvisibleGadget Invisible { get; } = new(); public BubbleEffect Bubble { get; } = new(); public BaseballGadget Baseball { get; } = new(); public PlayerAppearance Appearance { get; } = new(); public Vr01FloorState FloorState { get; } = new(); public Vector3 BubbleRoot { get; private set; } public float BodyFactor { get; private set; } = OriginalBodySupport.JimmyFactor; public float MaximumSpeed { get; private set; } = RecoveredMotion.MaximumSpeed; public float Pitch { get; private set; } public float Roll { get; private set; } public bool TracksBubbleOrientation { get; private set; } public int BubbleBounces { get; private set; } public int GadgetMode { get => gadgetMode; set { var previousPose=Pose; if (gadgetMode == 0) ReleaseBubble(); if (gadgetMode == 2) Invisible.Release(); if (gadgetMode == 6) Baseball.Release(); gadgetMode = -1; if (value == 0) { if (Energy <= 0 && !IgnoresGadgetEnergy || Bubble.Active || Bubble.Expanding || Bubble.Collapsing) return; InteractionRadius=160; BodyFactor=.415f; movementMode=2; MaximumSpeed=1350; bubblePose=previousPose; TracksBubbleOrientation=true; gadgetMode=0; Bubble.Start(); if (!bubbleLoop) { GadgetSound?.Invoke(2,true); bubbleLoop=true; } return; } if (value == 2 && !Invisible.Equip(Energy, IgnoresGadgetEnergy)) return; if (value == 6) Baseball.Equip(); gadgetMode = value; } } public bool IgnoresGadgetEnergy => PlayerEnergy.IsTutorial(LevelCode); public float Energy { get => energy.Value; set => energy.Value = value; } public bool LowEnergyWarning => energy.LowWarning; public event Action? EnergySound; public event Action? GadgetSound; public event Action? BubbleSoundStopped; public event Action? ScoreChanged; public event Action? DefaultGadgetRequested; //Source260/live15C serves both body collision and contact tests. The name //predates source-body integration; burst100 is not an interaction-only size. public float InteractionRadius { get; private set; } = 60; public bool JetpackEffectVisible { get; private set; } public Action? InputActions { get; set; } public bool Shooting { get; private set; } public float JetpackRemaining => jumpState.EffectRemaining; public int JumpState => jumpState.JumpState; public float JumpHoldSeconds => jumpState.HoldSeconds; public int Bursts { get; private set; } public float BodyHeight { get; } public Vector3 Position { get; private set; } // Feet, not original actor root. public Vector3 Velocity { get; private set; } public Vector3 PendingImpulse => pendingImpulse; public int MovementMode => movementMode; // Fresh game registers before Jimmy. A retained Jimmy precedes the newly // appended destination game, whose input callback therefore runs later. public bool InputAfterPlayerUpdate { get; set; } public float Yaw { get; private set; } public float Speed { get; private set; } public float PublishedSpeed { get; private set; } public bool UsesOriginalBody => originalBody != null; public float TurnRate { get; private set; } public bool Grounded { get; private set; } public PlayerPose Pose => Noclip ? Velocity.LengthSquared() > 0 ? PlayerPose.Fly : PlayerPose.Idle : GadgetMode == 0 ? bubblePose : pendingImpulse.Y > 0 ? PlayerPose.Jump : Grounded ? Shooting ? PlayerPose.Shoot : Speed < -1 ? PlayerPose.Backpedal : Speed > 1 ? PlayerPose.Run : PlayerPose.Idle : jumpState.JumpState == 3 && jumpState.EffectRemaining > 0 ? PlayerPose.Fly : !forceFall && Velocity.Y > 0 ? PlayerPose.Jump : PlayerPose.Fall; public int Steps { get; private set; } public int PhysicsSteps { get; private set; } public int ControllerSteps { get; private set; } public int EffectSteps { get; private set; } public int CeilingHits { get; private set; } public int Jumps { get; private set; } public int Landings { get; private set; } public int WallHits { get; private set; } public float Travel { get; private set; } public float MaximumRise { get; private set; } public Func? DynamicRootResolver { get; set; } public Vector3 ActorRoot => Position + Vector3.UnitY * rootHeight; public Vector3 CameraEye { get; private set; } public Vector3 CameraTarget => ActorRoot + new Vector3(0, 80 + 1.9f * Baseball.CameraPitch, 0); public Matrix4x4 Model => Matrix4x4.CreateRotationZ(-(TracksBubbleOrientation?Roll:0) * MathF.PI / 180) * Matrix4x4.CreateRotationX(-(TracksBubbleOrientation?Pitch:0) * MathF.PI / 180) * Matrix4x4.CreateRotationY(-Yaw * MathF.PI / 180) * Matrix4x4.CreateTranslation(Position - new Vector3(0, modelMinimumY, 0)); public LabSimulation(SceneCollision collision, Mesh standingPose, Vector3 start, float yaw, Func? cameraRay = null, Func? ceilingRay = null, OriginalStaticCollision? originalCollision = null, PlayerEnergy? energy = null) { this.collision = collision; this.cameraRay = cameraRay; this.ceilingRay = ceilingRay; originalBody = originalCollision == null ? null : new OriginalBodyPhysics(originalCollision); this.energy = energy ?? new PlayerEnergy(); Invisible.AlphaRequested += Appearance.SetAlpha; Invisible.BlendRequested += Appearance.SetBlend; Baseball.Thrown += () => GadgetSound?.Invoke(10,false); sourceStart = start; startYaw = yaw; var bounds = standingPose.Bounds(); modelMinimumY = bounds.Min.Y; BodyHeight = bounds.Max.Y - bounds.Min.Y; var floor = collision.GroundHeight(start, 2500) ?? throw new InvalidDataException("No support below GAM startpoint"); startFloor = floor; // Normal Jimmy PostLoad4236A3..BA and support47BAE1 place the actor // root at floor+60*1.265. Serialized spawnY is settled by physics. // Feet collision and sole-based visual placement remain provisional. rootHeight = OriginalBodySupport.JimmyRadius * OriginalBodySupport.JimmyFactor; Reset(); } public void Reset() { if (gadgetMode == 0) { GadgetMode=-1; DefaultGadgetRequested?.Invoke(); } if (gadgetMode == 2) gadgetMode = -1; Invisible.Reset(); Baseball.Reset(); if (gadgetMode == 6) gadgetMode = -1; Bubble.Reset(); FloorState.Reset(); Appearance.Reset(); retainedSupportMaterial=null; Pitch=Roll=targetPitch=targetRoll=0; BubbleBounces=0; TracksBubbleOrientation=false; MaximumSpeed=RecoveredMotion.MaximumSpeed; BodyFactor=OriginalBodySupport.JimmyFactor; var floor = collision.GroundHeight(sourceStart, 2500)!.Value; Position = new(sourceStart.X, floor + (UsesOriginalBody ? 0 : SceneCollision.Skin), sourceStart.Z); Velocity = Vector3.Zero; Yaw = targetYaw = startYaw; Speed = PublishedSpeed = TurnRate = extraAirAcceleration = shadowDistance = 0; lateralContribution = 0; pendingImpulse = Vector3.Zero; movementMode = 0; jumpState = default; forceFall = JetpackEffectVisible = false; Shooting = false; InteractionRadius = 60; Bursts = 0; Grounded = true; Noclip = HasNoclipEntry = false; Steps = Jumps = Landings = WallHits = 0; PhysicsSteps = ControllerSteps = EffectSteps = CeilingHits = 0; Travel = MaximumRise = 0; CameraEye = DesiredEye().Eye; } /// Jimmy PostLoad423A90..423ABF restores the saved RETURN root. /// Yaw remains the authored STRT yaw; the source stores only XYZ here. public void RestoreReturnRoot(Vector3 root) { if (!float.IsFinite(root.X) || !float.IsFinite(root.Y) || !float.IsFinite(root.Z)) throw new ArgumentOutOfRangeException(nameof(root)); Position = root - Vector3.UnitY * rootHeight; CameraEye = DesiredEye().Eye; } public PlayerLevelState? CaptureLevelState(int selectedGadget) => Noclip ? null : new(LevelCode, selectedGadget, movementMode, jumpState.HoldSeconds, jumpState.EffectRemaining); /// Apply after destination construction. Init re-applies authored /// body vectors and clears speed/turn; PostLoad resets jump, not these scalars. /// Grounding and the next controller/fire tick may change them independently. public bool ApplyRetainedLevelState(PlayerLevelState state) { ArgumentNullException.ThrowIfNull(state); if (!state.SupportsDestination(LevelCode)) return false; if (state.MovementMode is < 0 or > 1 || !float.IsFinite(state.HoldSeconds) || state.HoldSeconds < 0 || !float.IsFinite(state.EffectRemaining)) throw new ArgumentOutOfRangeException(nameof(state)); movementMode = state.MovementMode; jumpState = new(0, state.HoldSeconds, state.EffectRemaining); return true; } // EXE 0x47F940 truncates, then degree lookup masks to the 16384-entry table. // Table generated with modern trig; x87 bit-identical table recovery is pending. public static (float Sin, float Cos) Trig(float degrees) { var index = (int)(degrees * 45.5111122f) & 0x3fff; var radians = index * (Math.Tau / 16384); return ((float)Math.Sin(radians), (float)Math.Cos(radians)); } public void Step(PlayerInput input, bool controlled = true, bool? anyControlled = null) { if (Noclip) { StepNoclip(input); Bubble.Step(FixedStepClock.Step); //Modern flight skips body/input, not the released owned sprite's fade. return; } //47E554 global body integration precedes473740 registry callbacks. // This reconstructs the player/input/fire partial order, not the full // scene registry, original cadence or original collision response. StepPhysics(); if (controlled && !InputAfterPlayerUpdate) StepInput(input); //42469F..4246DC runs independently of raw ownership. if (Grounded) { InteractionRadius = GadgetMode == 0 ? 160 : 60; if (GadgetMode==0) bubblePose=PlayerPose.Idle; } //424BE0..424C34 runs this wrapper before437940's ownership gate. StepCeiling(); StepFloorPolicy(); //437940's base40E050, before the input-identity gate. if (controlled) StepPlayer(input); Invisible.Step(FixedStepClock.Step, anyControlled ?? controlled, input.Fire, input.Jump, Energy, IgnoresGadgetEnergy, AdjustEnergy); if (LevelCode == "VR01") FloorState.Step(FixedStepClock.Step,Appearance.SetColor); var effect = JetpackBurst.StepEffect(jumpState, Grounded, FixedStepClock.Step, Energy, LevelCode); jumpState = effect.State; JetpackEffectVisible = effect.Visible; if (effect.Visible) AdjustEnergy(-FixedStepClock.Step * JetpackBurst.EnergyPerSecond); EffectSteps++; Bubble.Step(FixedStepClock.Step); //Owned effect clock is not Jimmy input ownership. if (controlled && InputAfterPlayerUpdate) StepInput(input); Steps++; } /// 43A750 preparation clears speed and velocity XYZ only. Queued /// impulse, acceleration, mode, jump/hold and owned fire timer survive. public void PrepareForScript() { Speed = 0; Velocity = Vector3.Zero; } public void StopForPrimaryFire() => Speed = 0; public void SetShooting(bool shooting) => Shooting = shooting; public void AdjustEnergy(float delta) => energy.Adjust(delta, LevelCode, id => EnergySound?.Invoke(id)); private void ReleaseBubble() { movementMode=0; MaximumSpeed=650; Bubble.Stop(); Bubble.ClearExpansion(); if (bubbleLoop) BubbleSoundStopped?.Invoke(); bubbleLoop=false; InteractionRadius=60; BodyFactor=OriginalBodySupport.JimmyFactor; } public void FlattenOrientation() { Pitch=Roll=0; } public void SeedBubbleTilt(Vector3 euler) { if (TracksBubbleOrientation) return; Pitch=targetPitch=euler.X; Roll=targetRoll=euler.Z; } private void StepFloorPolicy() { if (LevelCode!="VR01" || originalBody==null) return; var effect=FloorState.Visit(retainedSupportMaterial,GadgetMode); if (effect.Entered) { GadgetSound?.Invoke(39,false); if (GadgetMode!=0) GadgetSound?.Invoke(190,false); } if (!effect.Damaged) return; AdjustEnergy(-5); ScoreChanged?.Invoke(-5); CancelPoweredFlight(); } private void CancelPoweredFlight() { if (movementMode!=1) return; jumpState=jumpState with {JumpState=0,EffectRemaining=0}; forceFall=true; } private void StepCeiling() { if (Velocity.Y <= 0 || ceilingRay == null || ceilingRay(ActorRoot, ActorRoot + Vector3.UnitY * 150) == null) return; Velocity = Velocity with { Y = (float)Math.Min(-Velocity.Y * .6, -85) }; CeilingHits++; //425120 leaves hold, mode, pending impulse and acceleration intact. //Full sound/selected-gadget cleanup callbacks remain a separate gap. CancelPoweredFlight(); } /// Authored AI root/Euler writes. They do not reset body motion or /// destination yaw61C; the full logical/render Euler model remains separate. public void ApplyAuthoredTransform(Vector3 root, float yaw) { if (!float.IsFinite(root.X) || !float.IsFinite(root.Y) || !float.IsFinite(root.Z) || !float.IsFinite(yaw)) throw new ArgumentOutOfRangeException(nameof(root)); Position = root - Vector3.UnitY * rootHeight; Yaw = yaw; } /// Modern debug movement; never serialized into original save state. public bool SetNoclip(bool enabled) { if (enabled == Noclip) return false; if (enabled) { if (gadgetMode==0) { GadgetMode=-1; DefaultGadgetRequested?.Invoke(); } noclipEntry = Position; noclipEntryYaw = Yaw; HasNoclipEntry = true; } var returned = !enabled && !collision.CanOccupy(Position, BodyRadius, BodyHeight); if (returned) { Position = noclipEntry; Yaw = targetYaw = noclipEntryYaw; } Noclip = enabled; StopDebugMotion(); Grounded = false; CameraEye = DesiredEye().Eye; return returned; } public void StopDebugMotion() { if (gadgetMode==0) { GadgetMode=-1; DefaultGadgetRequested?.Invoke(); } Shooting = false; Velocity = pendingImpulse = Vector3.Zero; Speed = PublishedSpeed = TurnRate = extraAirAcceleration = lateralContribution = 0; jumpState = default; movementMode = 0; forceFall = JetpackEffectVisible = false; targetYaw = Yaw; } public bool ReturnToNoclipEntry() { if (!HasNoclipEntry) return false; Position = noclipEntry; Yaw = targetYaw = noclipEntryYaw; StopDebugMotion(); Grounded = false; CameraEye = DesiredEye().Eye; return true; } private void StepNoclip(PlayerInput input) { if (!float.IsFinite(NoclipSpeed) || NoclipSpeed <= 0 || NoclipSpeed > 10000) throw new ArgumentOutOfRangeException(nameof(NoclipSpeed)); const float dt = FixedStepClock.Step; Yaw = targetYaw = (Yaw + ((input.Left ? 1 : 0) - (input.Right ? 1 : 0)) * 90 * dt) % 360; var (sin, cos) = Trig(Yaw); var direction = new Vector3(-sin, 0, cos) * ((input.Forward ? 1 : 0) - (input.Backward ? 1 : 0)) + new Vector3(cos, 0, sin) * ((input.StrafeRight ? 1 : 0) - (input.StrafeLeft ? 1 : 0)) + Vector3.UnitY * ((input.Rise ? 1 : 0) - (input.Descend ? 1 : 0)); if (direction.LengthSquared() > 1) direction = Vector3.Normalize(direction); Velocity = direction * NoclipSpeed * (input.Fast ? 3 : 1); var delta = Velocity * dt; Position += delta; Travel += new Vector2(delta.X, delta.Z).Length(); MaximumRise = Math.Max(MaximumRise, Position.Y - startFloor); Grounded = false; Steps++; CameraEye = DesiredEye().Eye; } private void StepInput(PlayerInput input) { const float dt = FixedStepClock.Step; lateralContribution = 0; //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); } else if (movementMode==2) { var steering=BubbleMotion.StepInput(Speed,TurnRate,input,Grounded,dt,MaximumSpeed); Speed=steering.Speed; TurnRate=steering.TurnRate; targetPitch=steering.TargetPitch; targetRoll=steering.TargetRoll; targetYaw=Yaw; } else { var steering = AirSteering.Step(Speed, TurnRate, input, dt,MaximumSpeed); Speed = steering.Speed; TurnRate = steering.TurnRate; 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. targetYaw = Yaw; } Baseball.StepCameraInput(input); StepCamera(); //438BC0/439900 input path owns follow; still provisional geometry/state. if (movementMode==2) { AdjustEnergy(-dt*.5f); if (Energy<=0) { GadgetMode=-1; DefaultGadgetRequested?.Invoke(); } //4262A5 continues placement even if depletion just cleaned the mode. var direction=ActorRoot+Vector3.UnitY*100-CameraEye; direction=direction.LengthSquared()>0 ? Vector3.Normalize(direction) : Vector3.Zero; BubbleRoot=ActorRoot+Vector3.UnitY*50-direction*80; } InputActions?.Invoke(input); Baseball.StepInput(input,ActorRoot,new(Pitch,Yaw,Roll),Grounded,Energy,IgnoresGadgetEnergy, StopForPrimaryFire,SetShooting,AdjustEnergy); } 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); Velocity=bubble.Velocity; Yaw=bubble.Yaw; Speed=bubble.Speed; PublishedSpeed=Speed; 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; else if (Grounded) { 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; 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, JetpackInventoryState?.Invoke() ?? 0, Energy, LevelCode, GadgetMode, dt, extraAirAcceleration)); jumpState = air.State; extraAirAcceleration = air.ExtraAccelerationY; pendingImpulse += new Vector3(0, air.ImpulseY, 0); if (air.ImpulseY != 0) Jumps++; if (air.MovementModeOverride is { } mode) movementMode = mode; if (air.VelocityYOverride is { } vertical) velocity.Y = vertical; if (air.RadiusOverride is { } radius) InteractionRadius = radius; if (air.Pose == JetpackPose.Fall) forceFall = true; else if (air.Pose is JetpackPose.Jump or JetpackPose.Fly) forceFall = false; if (air.StartGadget) Bursts++; Velocity = velocity; // Produced body state is consumed by the next physics pass. PublishedSpeed = Speed; //437C22..437C2D: controller608 -> body160. } private void StepPhysics() { PhysicsSteps++; const float dt = FixedStepClock.Step; if (originalBody != null) { StepOriginalPhysics(); return; } var wasGrounded = Grounded; var velocity = Velocity; // Keep the existing capsule/gravity adapter until C4 recovers Jimmy's // support/response. Source479DF7..479E54 cancels gravity and vertical // velocity when global geometry4F69E5 is disabled, not when grounded. // This adapter does not model that separate source debug/global gate. var displacement = RecoveredMotion.Integrate(ref velocity, ref pendingImpulse, Vector3.UnitY * extraAirAcceleration, RecoveredMotion.Gravity, dt); var before = Position; var result = collision.Move(Position, displacement, BodyRadius, BodyHeight); Position = result.Position; if (DynamicRootResolver != null) { var root = ActorRoot; var resolved = DynamicRootResolver(before + Vector3.UnitY * rootHeight, root, InteractionRadius); if (resolved != root) { // Original47A5E0 re-clips against static geometry before storing // the new root. Here both kernels remain explicitly provisional. result = collision.Move(Position, resolved - root, BodyRadius, BodyHeight); Position = result.Position; } } Grounded = result.Grounded && velocity.Y <= 0; if (Grounded && velocity.Y < 0 || result.HitCeiling && velocity.Y > 0 && ceilingRay == null) velocity.Y = 0; if (Grounded) { extraAirAcceleration = 0; forceFall = false; } Velocity = velocity; if (!wasGrounded && Grounded) Landings++; if (result.HitWall) WallHits++; Travel += Vector2.Distance(new(before.X, before.Z), new(Position.X, Position.Z)); MaximumRise = Math.Max(MaximumRise, Position.Y - startFloor); } private void StepOriginalPhysics() { if (DynamicRootResolver != null) throw new NotSupportedException("Original ordinary-body subset cannot use the provisional dynamic resolver"); var before = Position; var result = originalBody!.Step(new(ActorRoot, Velocity, Vector3.UnitY * extraAirAcceleration, pendingImpulse, Grounded, PublishedSpeed), FixedStepClock.Step, InteractionRadius,BodyFactor); if (result.SupportHit is { } hit) retainedSupportMaterial=originalBody.MaterialFor(hit); Position = result.Body.Position - Vector3.UnitY * rootHeight; Velocity = result.Body.Velocity; pendingImpulse = result.Body.Impulse; extraAirAcceleration = result.Body.Acceleration.Y; Grounded = result.Body.Supported; if (Grounded) forceFall = false; if (result.Landing != null) Landings++; if (result.Contact is { StoredNormal.Y: > -.7f }) WallHits++; Travel += Vector2.Distance(new(before.X, before.Z), new(Position.X, Position.Z)); MaximumRise = Math.Max(MaximumRise, Position.Y - startFloor); } private void StepCamera() { const float dt = FixedStepClock.Step; var desired = DesiredEye(); var delta = (desired.Eye - CameraEye) * new Vector3(1.6f, 1.2f, 1.6f) * desired.Gain * dt; CameraEye = cameraRay == null ? collision.ClipCamera(CameraTarget, CameraEye + delta) : CameraEye + delta; } private (Vector3 Eye, float Gain) DesiredEye() { var (sin, cos) = Trig(Yaw); var eye = ActorRoot + new Vector3(sin * 350, Baseball.CameraHeight - 2 * Baseball.CameraPitch, -cos * 350); if (Noclip) return (eye, 1); // Debug exploration also bypasses camera obstruction. if (cameraRay == null) return (collision.ClipCamera(CameraTarget, eye), 1); //43B820: query from the computed look target; first accepted static hit //moves desired eye25% toward look and returns follow gain1.5. No radius //or second sweep after interpolation occurs in that source callback. return cameraRay(CameraTarget, eye) is { } hit ? (CameraTarget - (CameraTarget - hit.Position) * .75f, 1.5f) : (eye, 1); } 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}, controller={ControllerSteps}, physics={PhysicsSteps}, effect={EffectSteps}, travel={Travel:F2}, jumps={Jumps}, landings={Landings}, max rise={MaximumRise:F2}, wall hits={WallHits}, ceiling hits={CeilingHits}, grounded={Grounded}, feet={Position}, body={(UsesOriginalBody ? "source ordinary" : "provisional capsule")}."; }