diff --git a/src/RustToDust.Ymir/WalkerLocomotion.cs b/src/RustToDust.Ymir/WalkerLocomotion.cs index 4a74d9d..9959869 100644 --- a/src/RustToDust.Ymir/WalkerLocomotion.cs +++ b/src/RustToDust.Ymir/WalkerLocomotion.cs @@ -1518,7 +1518,7 @@ namespace RustToDust.Ymir } Vector3 plantHip = comPos + curPelvisW + Vector3.Transform(geom.Legs[i].HipInCom * scale, qYaw); float plantAnkleH = geom.Legs[i].AnkleH * scale; - float plantMaxReach = geom.Legs[i].MaxLegReach * scale * 0.955f; + float plantMaxReach = geom.Legs[i].MaxLegReach * scale * 0.985f; var gHit = SampleGroundAt(terrain, world, plantSource.X, plantSource.Z, comPos.Y + 0.8f); Vector3 landedSole = new(plantSource.X, gHit.SurfaceY, plantSource.Z); Vector3 landedNorm = gHit.Normal; diff --git a/tests/RustToDust.Tests/CultNetMultiplayerTests.cs b/tests/RustToDust.Tests/CultNetMultiplayerTests.cs index 7a862dc..cbb5fab 100644 --- a/tests/RustToDust.Tests/CultNetMultiplayerTests.cs +++ b/tests/RustToDust.Tests/CultNetMultiplayerTests.cs @@ -797,6 +797,155 @@ namespace RustToDust.Tests "Client must receive Exemplar walker snapshot even under dense 12 quad-walker contention"); } + [Fact] + public void OptionA_WalkerReplication_ChassisSwapLegCount_PvsExitClears_AndIdlePostBlastSync() + { + // 1. Direct snapshot interpolation guards: LegCount mismatch & >4m teleport jump must snap cleanly to curr + var snap2Leg = new WalkerVisualSnapshot + { + HipYaw = 0f, + ComPos = new Vector3(10f, 4f, 10f), + PelvisOffset = Vector3.Zero, + LeanPitch = 0.05f, + LeanRoll = 0f, + Scale = 1f, + LegCount = 2, + IsArachnidUp = false, + IsDigitigrade = true, + LegSoles = new[] { new Vector3(9f, 0f, 10f), new Vector3(11f, 0f, 10f), Vector3.Zero, Vector3.Zero } + }; + var snap4Leg = new WalkerVisualSnapshot + { + HipYaw = 1.2f, + ComPos = new Vector3(12f, 5f, 12f), + PelvisOffset = new Vector3(0f, -0.1f, 0f), + LeanPitch = -0.05f, + LeanRoll = 0.04f, + Scale = 1.15f, + LegCount = 4, + IsArachnidUp = false, + IsDigitigrade = false, + LegSoles = new[] + { + new Vector3(10f, 0f, 10f), + new Vector3(14f, 0f, 10f), + new Vector3(10f, 0f, 14f), + new Vector3(14f, 0f, 14f) + } + }; + var swapInterp = WalkerVisualSnapshot.Interpolate(in snap2Leg, in snap4Leg, 0.5f); + Assert.Equal(4, swapInterp.LegCount); + Assert.Equal(snap4Leg.ComPos, swapInterp.ComPos); + + var snap4Far = snap4Leg; + snap4Far.ComPos = new Vector3(95f, 5f, 95f); + var jumpInterp = WalkerVisualSnapshot.Interpolate(in snap4Leg, in snap4Far, 0.5f); + Assert.Equal(snap4Far.ComPos, jumpInterp.ComPos); + + // 2. End-to-end ServerMatchHost + RemoteArenaSession checks + using var host = new ServerMatchHost(IPAddress.Loopback, 0, seed: 42, ArenaMapKind.Desert, maxHumans: 12, autoRestartSec: 0); + var ep = new IPEndPoint(IPAddress.Loopback, host.BoundPort); + using var client = new RemoteArenaSession(ep, "NetWalker"); + long nowMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); + Assert.True(PumpUntil(host, new[] { client }, () => client.IsJoined, ref nowMs, 3000)); + int slot = client.LocalContenderId; + int rivalId = (slot + 1) % MatchState.ContenderCount; + + // Isolate others far away; put rival close to client as 2-leg Breaker + for (int i = 0; i < MatchState.ContenderCount; i++) + { + if (i == slot) host.Session.SetContenderPose(i, 0f, 0f, 0f); + else if (i == rivalId) host.Session.SetContenderPose(i, 16f, 0f, 0f); + else host.Session.SetContenderPose(i, 900f + i * 20f, 900f); + } + host.Session.State.SpawnChassisDrop(16f, 0f, Catalog.Breaker); + Assert.True(host.Session.TrySwapNearbyChassis(rivalId)); + + bool sawRival2Leg = PumpUntil( + host, + new[] { client }, + () => client.TrySampleInterpolatedWalkerPose(true, rivalId, 1f, out var s) && s.LegCount == 2, + ref nowMs, + 2500); + Assert.True(sawRival2Leg, "Expected client to observe 2-leg rival Breaker snapshot"); + + // Swap rival to 4-leg Bastion via genuine chassis swap event (must emit ContenderLoadoutEvent & clear timeline) + var rival = host.Session.State.Contenders[rivalId]; + host.Session.State.SpawnChassisDrop(rival.X, rival.Z, Catalog.Bastion); + Assert.True(host.Session.TrySwapNearbyChassis(rivalId)); + + bool sawRival4Leg = PumpUntil( + host, + new[] { client }, + () => client.TrySampleInterpolatedWalkerPose(true, rivalId, 1f, out var s) && s.LegCount == 4, + ref nowMs, + 2500); + Assert.True(sawRival4Leg, "Expected client to swap rival walker timeline cleanly to 4-leg Bastion"); + + // Rival leaves PVS (>450m away) -> client must clear timeline rather than serving stale pose + host.Session.SetContenderPose(rivalId, 650f, 650f, 0f); + bool rivalCleared = PumpUntil( + host, + new[] { client }, + () => !client.TrySampleInterpolatedWalkerPose(true, rivalId, 1f, out _), + ref nowMs, + 2500); + Assert.True(rivalCleared, "Expected client to clear rival walker timeline upon PVS exit"); + + // Rival re-enters PVS at (-18, 0) -> must immediately appear near -18 rather than sliding from old +16 position! + host.Session.SetContenderPose(rivalId, -18f, 0f, 0f); + WalkerVisualSnapshot reenterSnap = default; + bool reentered = PumpUntil( + host, + new[] { client }, + () => client.TrySampleInterpolatedWalkerPose(true, rivalId, 0.25f, out reenterSnap), + ref nowMs, + 2500); + Assert.True(reentered, "Expected rival walker to re-enter client PVS"); + Assert.True(reenterSnap.ComPos.X < -10f, + $"Expected rival re-entry to snap near X=-18 instead of blending from stale X=+16 (got X={reenterSnap.ComPos.X:F2})"); + + // 3. Idle local walker post-blast server reconciliation (_unackedInputs.Count == 0): + // Ensure local client is grounded and settled with NO pending movement inputs, then apply upward blast on server + var localContender = host.Session.State.Contenders[slot]; + var localBody = host.Session.GetContenderBody(slot)!.Value; + var localWs = host.Session.GetWalkerState(true, slot)!; + var view = host.Session.World.View; + int lane = localBody.Lane; + + Assert.True(client.TrySampleInterpolatedWalkerPose(true, slot, 1f, out var preBlastSnap), + "Expected local walker prediction snapshot while grounded idle"); + float preBlastY = preBlastSnap.ComPos.Y; + + const float blastVy = 9.0f; + localWs.NotifyExternalUpwardImpulse(blastVy); + host.Session.World.ApplyImpulse(lane, (0f, view.Mass[lane] * blastVy, 0f), (view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane])); + + bool sawBlastClimb = false; + for (int t = 0; t < 25; t++) + { + nowMs += 16; + host.StepOnce(nowMs); + client.PumpNetwork(nowMs); + client.BeginRenderFrame(1.0 / 60.0, 1f); + Thread.Sleep(1); + if (client.TrySampleInterpolatedWalkerPose(true, slot, 1f, out var postBlastSnap)) + { + if (postBlastSnap.ComPos.Y >= preBlastY + 0.40f) + { + sawBlastClimb = true; + for (int i = 0; i < postBlastSnap.LegCount; i++) + { + float surfY = host.Session.State.Terrain.SampleHeight(postBlastSnap.LegSoles[i].X, postBlastSnap.LegSoles[i].Z); + Assert.True(postBlastSnap.LegSoles[i].Y >= surfY - 0.10f, + $"Idle post-blast pred foot {i} dove underground ({postBlastSnap.LegSoles[i].Y:F2} < {surfY:F2})"); + } + } + } + } + Assert.True(sawBlastClimb, "Idle local client must sync _predWalker smoothly to server upward blast without stale prediction lock"); + } + private static byte[] EncodeRudpLatestDatagram(byte[] frameBytes, uint sequence) => CultNetRudpPacketCodec.Encode(new CultNetRudpPacket { diff --git a/tests/RustToDust.Tests/HybridBWalkerTests.cs b/tests/RustToDust.Tests/HybridBWalkerTests.cs index 092b512..e3ff010 100644 --- a/tests/RustToDust.Tests/HybridBWalkerTests.cs +++ b/tests/RustToDust.Tests/HybridBWalkerTests.cs @@ -1822,5 +1822,331 @@ namespace RustToDust.Tests Assert.InRange(s0.LeanPitch, 0.10f, 0.12f); Assert.InRange(s0.LeanRoll, -0.15f, -0.13f); } + + [Fact] + public void OptionA_AirborneFreefall_FeetClampAboveGround_AndStayWithin3DReach() + { + var specs = new[] { Catalog.Breaker, Catalog.Spectre, Catalog.Manticore, Catalog.Bastion }; + foreach (var spec in specs) + { + foreach (var map in new[] { ArenaMapKind.Desert, ArenaMapKind.Sion }) + { + using var session = new ArenaSession(seed: 42, mapKind: map, slot0Human: true); + for (int i = 1; i < session.State.Contenders.Count; i++) + { + session.SetContenderPose(i, 900f + i * 16f, 900f); + } + + float dropX = 0f; + float dropZ = 0f; + if (map == ArenaMapKind.Sion && session.State.SionMap is { } sion) + { + bool found = false; + for (float r = 0f; r <= 300f && !found; r += 15f) + { + for (int a = 0; a < 24 && !found; a++) + { + float ang = a * (MathF.Tau / 24f); + float tx = MathF.Cos(ang) * r; + float tz = MathF.Sin(ang) * r; + if (!sion.IsInsideAnyBuildingXz(tx, tz, 12f) && + session.State.Terrain.SampleNormal(tx, tz).Ny >= 0.96f) + { + dropX = tx; + dropZ = tz; + found = true; + } + } + } + Assert.True(found, "Expected flat open spot on Sion"); + } + + session.SetContenderPose(0, dropX, dropZ, 0f); + session.State.SpawnChassisDrop(dropX, dropZ, spec); + Assert.True(session.TrySwapNearbyChassis(0), $"Failed swap to {spec.Id}"); + session.SetContenderPose(0, dropX, dropZ, 0f); + + var player = session.State.Contenders[0]; + var body = session.GetContenderBody(player.Id)!.Value; + var ws = session.GetWalkerState(true, player.Id)!; + var view = session.World.View; + int lane = body.Lane; + + float groundY = session.QueryDropSurface(dropX, dropZ, 0f, 120f).SurfaceY; + float physHalfH = MatchRules.GetPhysicsHalfHeight(spec); + session.World.SetBodyMotion( + body, + position: (dropX, groundY + physHalfH + 16f, dropZ), + linearVelocity: (0f, -2.0f, 0f), + angularVelocity: (0f, 0f, 0f)); + WalkerLocomotion.PostStepWalker(ws, player.Grid, session.State.Terrain, session.World, body, view.Mass[lane], ArenaSession.FixedDt); + Assert.True(ws.IsAirborne, $"{spec.Id} ({map}): must start airborne at +16m"); + + Vector3[] prevSoles = (Vector3[])ws.FootSole.Clone(); + bool sawAirborne = false; + bool landed = false; + int settledTicks = 0; + + for (int t = 0; t < 240; t++) + { + session.SetHumanInput(0, new PlayerInput(0.35f, 0f, dropX, dropZ + 50f, false, false, false)); + session.Step(); + + var comPos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]); + var qYaw = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW); + + for (int i = 0; i < ws.Geom.LegCount; i++) + { + Vector3 sole = ws.FootSole[i]; + float surfUnderFoot = session.QueryDropSurface(sole.X, sole.Z, 0f, comPos.Y + 1.0f).SurfaceY; + if (ws.IsAirborne) + { + sawAirborne = true; + Assert.True(sole.Y >= surfUnderFoot - 0.05f, + $"{spec.Id} ({map}) tick {t} leg {i}: airborne foot plunged underground ({sole.Y:F3} < {surfUnderFoot:F3})"); + } + + Vector3 hipWorld = comPos + ws.PelvisOffset + Vector3.Transform(ws.Geom.Legs[i].HipInCom * ws.GeomScale, qYaw); + Vector3 ankleWorld = sole + new Vector3(0f, ws.Geom.Legs[i].AnkleH * ws.GeomScale, 0f); + float dist3D = Vector3.Distance(ankleWorld, hipWorld); + float maxReach = ws.Geom.Legs[i].MaxLegReach * ws.GeomScale; + Assert.True(dist3D <= maxReach + 0.10f, + $"{spec.Id} ({map}) tick {t} leg {i}: 3D reach overflow {dist3D:F3} > {maxReach:F3}"); + + float footDelta = Vector3.Distance(sole, prevSoles[i]); + float maxAllowedDelta = 1.25f * MathF.Max(1f, ws.GeomScale); + Assert.True(footDelta <= maxAllowedDelta, + $"{spec.Id} ({map}) tick {t} leg {i}: foot teleport delta {footDelta:F3}m > {maxAllowedDelta:F3}m"); + prevSoles[i] = sole; + } + + if (!ws.IsAirborne) + { + landed = true; + settledTicks++; + if (settledTicks >= 20) break; + } + } + + Assert.True(sawAirborne, $"{spec.Id} ({map}): never observed airborne state"); + Assert.True(landed, $"{spec.Id} ({map}): walker failed to land within 240 ticks"); + } + } + } + + [Fact] + public void OptionA_SteepSionAndDesertSlopes_ReachClamped_KestrelUphillGrounded_LowBlastNotZeroed() + { + // 1. Steep slope 3D reach & slip check for Bastion & Manticore on Sion steep hill + Desert slope + using (var sionSession = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true)) + { + for (int i = 1; i < sionSession.State.Contenders.Count; i++) + { + sionSession.SetContenderPose(i, 900f + i * 16f, 900f); + } + + var sion = sionSession.State.SionMap!; + (float X, float Z, float Yaw) steepSite = default; + bool foundSteep = false; + float bestMinNy = 1f; + for (float r = 40f; r <= 950f; r += 20f) + { + for (int a = 0; a < 72; a++) + { + float ang = a * (MathF.Tau / 72f); + float x = MathF.Cos(ang) * r; + float z = MathF.Sin(ang) * r; + if (sion.IsInsideAnyBuildingXz(x, z, 14f)) continue; + var (nx, ny, nz) = sionSession.State.Terrain.SampleNormal(x, z); + if (ny >= 0.78f && ny <= 0.88f && ny < bestMinNy) + { + bestMinNy = ny; + steepSite = (x, z, MathF.Atan2(-nx, -nz)); + foundSteep = true; + } + } + } + Assert.True(foundSteep, "Expected a clear ~28-38 deg steep hill spot on Sion"); + + foreach (var spec in new[] { Catalog.Bastion, Catalog.Manticore }) + { + sionSession.SetContenderPose(0, steepSite.X, steepSite.Z, steepSite.Yaw + MathF.PI * 0.5f); + sionSession.State.SpawnChassisDrop(steepSite.X, steepSite.Z, spec); + Assert.True(sionSession.TrySwapNearbyChassis(0)); + sionSession.SetContenderPose(0, steepSite.X, steepSite.Z, steepSite.Yaw + MathF.PI * 0.5f); + + var player = sionSession.State.Contenders[0]; + var body = sionSession.GetContenderBody(player.Id)!.Value; + var ws = sionSession.GetWalkerState(true, player.Id)!; + var view = sionSession.World.View; + int lane = body.Lane; + Vector3[] prevSoles = (Vector3[])ws.FootSole.Clone(); + + for (int t = 0; t < 120; t++) + { + sionSession.SetHumanInput(0, new PlayerInput(1.0f, 0.25f, player.X + 40f * MathF.Sin(player.Yaw), player.Z + 40f * MathF.Cos(player.Yaw), false, false, false)); + sionSession.Step(); + + var comPos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]); + var qYaw = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW); + for (int i = 0; i < ws.Geom.LegCount; i++) + { + Vector3 hipWorld = comPos + ws.PelvisOffset + Vector3.Transform(ws.Geom.Legs[i].HipInCom * ws.GeomScale, qYaw); + Vector3 ankleWorld = ws.FootSole[i] + new Vector3(0f, ws.Geom.Legs[i].AnkleH * ws.GeomScale, 0f); + float dist3D = Vector3.Distance(ankleWorld, hipWorld); + float maxReach = ws.Geom.Legs[i].MaxLegReach * ws.GeomScale; + Assert.True(dist3D <= maxReach + 0.14f, + $"{spec.Id} Sion steep slope tick {t} leg {i}: 3D reach overflow {dist3D:F3} > {maxReach:F3}"); + + float footJump = Vector3.Distance(ws.FootSole[i], prevSoles[i]); + float maxJump = 1.6f * MathF.Max(1f, ws.GeomScale); + Assert.True(footJump <= maxJump, + $"{spec.Id} Sion steep slope tick {t} leg {i}: teleport jump {footJump:F3}m > {maxJump:F3}m"); + prevSoles[i] = ws.FootSole[i]; + } + } + } + + // 2. Kestrel sprinting straight uphill on steep Sion hill must stay grounded (no false blast launch from slopeVy) + sionSession.SetContenderPose(0, steepSite.X, steepSite.Z, steepSite.Yaw); + sionSession.State.SpawnChassisDrop(steepSite.X, steepSite.Z, Catalog.Kestrel); + Assert.True(sionSession.TrySwapNearbyChassis(0)); + sionSession.SetContenderPose(0, steepSite.X, steepSite.Z, steepSite.Yaw); + + var kestrel = sionSession.State.Contenders[0]; + var kBody = sionSession.GetContenderBody(kestrel.Id)!.Value; + var kWs = sionSession.GetWalkerState(true, kestrel.Id)!; + var kView = sionSession.World.View; + int kLane = kBody.Lane; + int airborneTicks = 0; + float maxVelY = 0f; + float maxAboveGround = 0f; + + for (int t = 0; t < 100; t++) + { + var (nx, ny, nz) = sionSession.State.Terrain.SampleNormal(kestrel.X, kestrel.Z); + float upYaw = (ny < 0.995f) ? MathF.Atan2(-nx, -nz) : steepSite.Yaw; + sionSession.SetHumanInput(0, new PlayerInput( + 1.0f, 0f, + kestrel.X + 40f * MathF.Sin(upYaw), + kestrel.Z + 40f * MathF.Cos(upYaw), + false, false, false)); + sionSession.Step(); + + if (kWs.IsAirborne) airborneTicks++; + maxVelY = MathF.Max(maxVelY, kView.LinearVelocityY[kLane]); + float surfY = sionSession.State.Terrain.SampleHeight(kestrel.X, kestrel.Z); + maxAboveGround = MathF.Max(maxAboveGround, kestrel.Y - (surfY + MatchRules.GetRideHeight(Catalog.Kestrel))); + } + + Assert.True(airborneTicks <= 3, $"Kestrel uphill sprint false-launched for {airborneTicks}/100 ticks!"); + Assert.True(maxVelY < 9.5f, $"Kestrel uphill sprint maxVelY spiked to {maxVelY:F2} m/s"); + Assert.True(maxAboveGround < 0.85f, $"Kestrel uphill sprint lifted {maxAboveGround:F2}m above ride height"); + } + + // 3. Low upward splash impulse (< 3.5 m/s) must NOT be zeroed out on tick 1 + foreach (var spec in new[] { Catalog.Breaker, Catalog.Bastion }) + { + using var session = new ArenaSession(seed: 7, mapKind: ArenaMapKind.Desert, slot0Human: true); + for (int i = 1; i < session.State.Contenders.Count; i++) + { + session.SetContenderPose(i, 900f + i * 16f, 900f); + } + + session.SetContenderPose(0, 0f, 0f, 0f); + session.State.SpawnChassisDrop(0f, 0f, spec); + Assert.True(session.TrySwapNearbyChassis(0)); + session.SetContenderPose(0, 0f, 0f, 0f); + + for (int settle = 0; settle < 10; settle++) + { + session.SetHumanInput(0, new PlayerInput(0f, 0f, 0f, 40f, false, false, false)); + session.Step(); + } + + var player = session.State.Contenders[0]; + var body = session.GetContenderBody(player.Id)!.Value; + var ws = session.GetWalkerState(true, player.Id)!; + var view = session.World.View; + int lane = body.Lane; + float mass = view.Mass[lane]; + const float impulseVy = 2.6f; // intentionally below legacy 3.5 m/s bug threshold + + ws.NotifyExternalUpwardImpulse(impulseVy); + session.World.ApplyImpulse(lane, (0f, mass * impulseVy, 0f), (view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane])); + session.SetHumanInput(0, new PlayerInput(0f, 0f, 0f, 40f, false, false, false)); + session.Step(); + + float postStepVy = view.LinearVelocityY[lane]; + Assert.True(postStepVy >= 1.5f, + $"{spec.Id}: genuine {impulseVy:F1} m/s upward blast was suppressed on tick 1 (postStepVy={postStepVy:F2})"); + } + } + + [Fact] + public void OptionA_SionRoofPodTouchdown_WalkerClearsRoofAndWalksUpright() + { + foreach (var spec in new[] { Catalog.Bastion, Catalog.Breaker }) + { + using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true); + var sion = session.State.SionMap!; + + SionBuildingAabb? flatRoofBldg = null; + for (int i = 0; i < sion.Buildings.Count; i++) + { + var b = sion.Buildings[i]; + if (b.Class == "Gebaeude Einzelhaus" && + b.HalfX >= 7f && b.HalfZ >= 7f && + (b.RoofY - b.GroundY) >= 10f && + MathF.Abs(b.CenterX) < 800f && MathF.Abs(b.CenterZ) < 800f) + { + var sample = session.QueryDropSurface(b.CenterX, b.CenterZ, 1.65f, b.RoofY + 20f); + if (sample.IsBuildingRoof && sample.IsFlatRoofValid) + { + flatRoofBldg = b; + break; + } + } + } + Assert.NotNull(flatRoofBldg); + var fr = flatRoofBldg!.Value; + + var player = session.State.Contenders[0]; + player.Grid.SwapChassis(spec); + var roofPod = session.State.OrbitalDrop.LaunchContenderPod( + player, 0, fr.CenterX, fr.CenterZ, 0f, session.QueryDropSurface, isRespawn: false); + roofPod.AllowFlatRoofLanding = true; + + for (int t = 0; t < 600 && !player.IsGroundedActive; t++) + { + session.SetHumanInput(0, new PlayerInput(0f, 0f, player.X, player.Z + 20f, false, false, false)); + session.Step(); + } + + Assert.True(player.IsGroundedActive, $"{spec.Id}: pod did not touch down within 600 ticks"); + Assert.True(player.TouchdownOnRoof, $"{spec.Id}: expected TouchdownOnRoof == true"); + + float expectedRideH = MatchRules.GetRideHeight(spec); + Assert.True(player.Y >= fr.RoofY + expectedRideH - 0.08f, + $"{spec.Id}: roof spawn buried below ride height ({player.Y:F3} < {fr.RoofY + expectedRideH - 0.08f:F3}, roofY={fr.RoofY:F3})"); + + var qLanding = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW); + var upLanding = Vector3.Transform(Vector3.UnitY, qLanding); + Assert.True(upLanding.Y >= 0.9995f, $"{spec.Id}: roof landing tilted! up.Y={upLanding.Y:F5}"); + + // Walk forward gently on roof: stays above roof height and stays upright + for (int t = 0; t < 25; t++) + { + session.SetHumanInput(0, new PlayerInput(0.45f, 0f, player.X, player.Z + 25f, false, false, false)); + session.Step(); + + var q = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW); + var up = Vector3.Transform(Vector3.UnitY, q); + Assert.True(up.Y >= 0.9995f, $"{spec.Id} roof walk tick {t}: tilted up.Y={up.Y:F5}"); + Assert.True(player.Y >= fr.RoofY + expectedRideH - 0.30f, + $"{spec.Id} roof walk tick {t}: sank into roof ({player.Y:F3} < {fr.RoofY + expectedRideH - 0.30f:F3})"); + } + } + } } }