From c789fe8af8373d2ac868e774800f3077e943dac7 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 5 Dec 2026 14:18:08 +0100 Subject: [PATCH] Walker locomotion: bold bent-knee strides, slope climb, crisp yaw stop --- src/RustToDust.Ymir/ArenaSession.cs | 6 +- src/RustToDust.Ymir/WalkerLocomotion.cs | 158 +++++--- tests/RustToDust.Tests/HybridBWalkerTests.cs | 382 +++++++++++++++++++ tests/RustToDust.Tests/TerrainTests.cs | 8 +- 4 files changed, 493 insertions(+), 61 deletions(-) diff --git a/src/RustToDust.Ymir/ArenaSession.cs b/src/RustToDust.Ymir/ArenaSession.cs index 6304d33..42e2bc4 100644 --- a/src/RustToDust.Ymir/ArenaSession.cs +++ b/src/RustToDust.Ymir/ArenaSession.cs @@ -1309,7 +1309,8 @@ namespace RustToDust.Ymir float iy = mass * (hx * hx + hz * hz) / 3f; Vector3 torque = ComputeRightingTorque(c.Grid.Spec, q, up, angVel, mass, terrainNormal, supportTorque, terrainBlend: 0.85f); - torque.Y = iy * (targetYawVel - angVel.Y) * 8f; + float yawGain = MathF.Abs(targetYawVel) < 1e-3f ? 26f : 16f; + torque.Y = iy * (targetYawVel - angVel.Y) * yawGain; view.ForceX[lane] = force.X; view.ForceY[lane] = force.Y; @@ -1647,7 +1648,8 @@ namespace RustToDust.Ymir float hx = view.Size0[lane]; float hz = view.Size2[lane]; float iy = mass * (hx * hx + hz * hz) / 3f; - torque.Y = iy * (targetYawVel - angVel.Y) * 8f; + float yawGain = MathF.Abs(targetYawVel) < 1e-3f ? 26f : 16f; + torque.Y = iy * (targetYawVel - angVel.Y) * yawGain; view.ForceX[lane] = force.X; view.ForceY[lane] = force.Y; diff --git a/src/RustToDust.Ymir/WalkerLocomotion.cs b/src/RustToDust.Ymir/WalkerLocomotion.cs index a803341..71b1d13 100644 --- a/src/RustToDust.Ymir/WalkerLocomotion.cs +++ b/src/RustToDust.Ymir/WalkerLocomotion.cs @@ -131,7 +131,7 @@ namespace RustToDust.Ymir var legs = new LegArray4(); legs[0] = new WalkerLegSpec(new Vector3(+1.0809f, +0.2170f, 0f), new Vector2(+1.0809f, 0f), 1.3203f, 1.4396f, 0f, 0.6249f, +1f, false); legs[1] = new WalkerLegSpec(new Vector3(-1.0809f, +0.2170f, 0f), new Vector2(-1.0809f, 0f), 1.3203f, 1.4396f, 0f, 0.6249f, +1f, false); - return new WalkerGeometrySpec("breaker", 2, false, false, 3.1456f, 2.99f, 0.55f, 0.80f, 0.58f, 1.65f, legs); + return new WalkerGeometrySpec("breaker", 2, false, false, 3.1456f, 2.99f, 0.55f, 0.80f, 0.73f, 2.40f, legs); } private static WalkerGeometrySpec BuildPaladin() @@ -139,7 +139,7 @@ namespace RustToDust.Ymir var legs = new LegArray4(); legs[0] = new WalkerLegSpec(new Vector3(+1.4853f, -0.2004f, +0.05f), new Vector2(+1.4853f, +0.05f), 1.9600f, 2.7200f, 0f, 1.0903f, +1f, false); legs[1] = new WalkerLegSpec(new Vector3(-1.5047f, -0.1983f, +0.05f), new Vector2(-1.5047f, +0.05f), 1.9600f, 2.7200f, 0f, 1.0903f, +1f, false); - return new WalkerGeometrySpec("paladin", 2, false, false, 5.6581f, 5.52f, 0.82f, 1.20f, 0.85f, 2.60f, legs); + return new WalkerGeometrySpec("paladin", 2, false, false, 5.6581f, 5.52f, 0.82f, 1.20f, 1.08f, 3.60f, legs); } private static WalkerGeometrySpec BuildRaptor() @@ -147,7 +147,7 @@ namespace RustToDust.Ymir var legs = new LegArray4(); legs[0] = new WalkerLegSpec(new Vector3(+1.4000f, +1.1712f, 0f), new Vector2(+1.4000f, 0f), 1.9000f, 1.6000f, 1.7600f, 0.8173f, +1f, false); legs[1] = new WalkerLegSpec(new Vector3(-1.4000f, +1.1712f, 0f), new Vector2(-1.4000f, 0f), 1.9000f, 1.6000f, 1.7600f, 0.8173f, +1f, false); - return new WalkerGeometrySpec("raptor", 2, true, false, 3.4937f, 3.52f, 0.62f, 0.95f, 0.70f, 2.40f, legs); + return new WalkerGeometrySpec("raptor", 2, true, false, 3.4937f, 3.52f, 0.62f, 0.95f, 0.88f, 3.30f, legs); } private static WalkerGeometrySpec BuildSpectre() @@ -155,7 +155,7 @@ namespace RustToDust.Ymir var legs = new LegArray4(); legs[0] = new WalkerLegSpec(new Vector3(+1.2500f, -0.0970f, +0.2227f), new Vector2(+1.2500f, +0.2227f), 1.7300f, 1.5340f, 1.8370f, 0.7385f, +1f, false); legs[1] = new WalkerLegSpec(new Vector3(-1.2500f, -0.1199f, +0.1996f), new Vector2(-1.2500f, +0.1996f), 1.7300f, 1.5340f, 1.8370f, 0.7385f, +1f, false); - return new WalkerGeometrySpec("spectre", 2, true, false, 4.4946f, 4.52f, 0.70f, 1.05f, 0.78f, 2.55f, legs); + return new WalkerGeometrySpec("spectre", 2, true, false, 4.4946f, 4.52f, 0.70f, 1.05f, 0.98f, 3.40f, legs); } private static WalkerGeometrySpec BuildKestrel() @@ -163,7 +163,7 @@ namespace RustToDust.Ymir var legs = new LegArray4(); legs[0] = new WalkerLegSpec(new Vector3(+1.3000f, +1.3093f, 0f), new Vector2(+1.3000f, 0f), 2.5760f, 3.0621f, 0f, 0.8500f, +1f, false); legs[1] = new WalkerLegSpec(new Vector3(-1.3000f, +1.3093f, 0f), new Vector2(-1.3000f, 0f), 2.6252f, 3.0551f, 0f, 0.8500f, +1f, false); - return new WalkerGeometrySpec("kestrel", 2, false, false, 4.8907f, 4.94f, 0.68f, 1.00f, 0.78f, 2.45f, legs); + return new WalkerGeometrySpec("kestrel", 2, false, false, 4.8907f, 4.94f, 0.68f, 1.00f, 0.98f, 3.60f, legs); } private static WalkerGeometrySpec BuildManticore() @@ -173,7 +173,7 @@ namespace RustToDust.Ymir legs[1] = new WalkerLegSpec(new Vector3(-1.4200f, -2.4075f, +1.95f), new Vector2(-2.259f, +3.319f), 1.4719f, 1.7205f, 0f, 0.4625f, +1f, true); legs[2] = new WalkerLegSpec(new Vector3(+1.4800f, -2.3875f, -1.90f), new Vector2(+2.483f, -3.479f), 1.5819f, 1.8711f, 0f, 0.4225f, +1f, true); legs[3] = new WalkerLegSpec(new Vector3(-1.4800f, -2.3875f, -1.90f), new Vector2(-2.483f, -3.479f), 1.5819f, 1.8711f, 0f, 0.4225f, +1f, true); - return new WalkerGeometrySpec("manticore", 4, false, true, 3.2500f, 3.28f, 0.45f, 0.55f, 0.62f, 1.65f, legs); + return new WalkerGeometrySpec("manticore", 4, false, true, 3.2500f, 3.28f, 0.45f, 0.55f, 0.78f, 2.25f, legs); } private static WalkerGeometrySpec BuildBastion() @@ -183,7 +183,7 @@ namespace RustToDust.Ymir legs[1] = new WalkerLegSpec(new Vector3(-4.2040f, -1.2643f, +4.2453f), new Vector2(-4.359f, +5.264f), 1.8041f, 1.2676f, 0f, 0.8855f, +1f, false); legs[2] = new WalkerLegSpec(new Vector3(+3.6871f, -0.1774f, -4.2453f), new Vector2(+5.033f, -6.736f), 4.4637f, 0.9009f, 0f, 0.7259f, -1f, false); legs[3] = new WalkerLegSpec(new Vector3(-3.6871f, -0.1774f, -4.2453f), new Vector2(-5.033f, -6.736f), 4.4637f, 0.9009f, 0f, 0.7259f, -1f, false); - return new WalkerGeometrySpec("bastion", 4, false, false, 4.8125f, 4.84f, 0.85f, 1.10f, 0.75f, 2.10f, legs); + return new WalkerGeometrySpec("bastion", 4, false, false, 4.8125f, 4.84f, 0.85f, 1.10f, 0.94f, 2.95f, legs); } } @@ -225,7 +225,7 @@ namespace RustToDust.Ymir public sealed class WalkerState { public const float ArenaGravity = 20f; - public const float FootFriction = 0.85f; + public const float FootFriction = 1.10f; public WalkerGeometrySpec Geom { get; private set; } public float GeomScale { get; private set; } @@ -576,9 +576,19 @@ namespace RustToDust.Ymir float desiredSpeed = MathF.Sqrt(desiredHorizVel.X * desiredHorizVel.X + desiredHorizVel.Z * desiredHorizVel.Z); float horizSpeed = MathF.Sqrt(vel.X * vel.X + vel.Z * vel.Z); - float baseRideHeight = geom.ModelRideHeight * scale; - float walkSpeedRatio = Math.Clamp(horizSpeed / MathF.Max(6f, grid.Spec.MaxSpeed), 0f, 1f); - float rideHeight = baseRideHeight - 0.06f * scale * walkSpeedRatio; + float baseRideHeight = geom.ModelRideHeight * scale; + float physHalfH = geom.ModelHalfHeight * scale * (n == 4 ? 0.62f : 0.72f); + float comGroundY = terrain.SampleHeight(comPos.X, comPos.Z); + Vector3 terrainNormal = WalkerState.SampleTerrainNormal(terrain, comPos.X, comPos.Z); + float crouchSpeedRatio = n == 4 + ? Math.Clamp(horizSpeed / MathF.Max(6f, grid.Spec.MaxSpeed), 0f, 1f) + : Math.Clamp(MathF.Max(horizSpeed, desiredSpeed) / MathF.Max(6f, grid.Spec.MaxSpeed * 0.40f), 0f, 1f); + float restCrouchFrac = n == 4 ? 0f : 0.045f; + float sprintCrouchFrac = n == 4 ? 0.05f : 0.095f; + float crouchFrac = restCrouchFrac + (sprintCrouchFrac - restCrouchFrac) * crouchSpeedRatio; + float crouchDrop = geom.ModelHalfHeight * scale * crouchFrac; + float minSafeRide = physHalfH + 0.45f * scale; + float rideHeight = MathF.Max(minSafeRide, baseRideHeight - crouchDrop); Vector3 fwd = Vector3.Transform(Vector3.UnitZ, qBody); fwd.Y = 0f; fwd = fwd.LengthSquared() > 1e-5f ? Vector3.Normalize(fwd) : Vector3.UnitZ; @@ -592,7 +602,6 @@ namespace RustToDust.Ymir } // Determine airborne state before gait step so floating mechs don't drag feet on the ground - float comGroundY = terrain.SampleHeight(comPos.X, comPos.Z); bool anyLegCanReachGround = false; for (int i = 0; i < n; i++) { @@ -634,7 +643,7 @@ namespace RustToDust.Ymir float overlap = n == 4 ? (anyLegSeverelyCrippled ? 0.28f : 0.12f) - : 0.10f; + : (anyLegSeverelyCrippled ? 0.12f : 0.06f); bool anySwinging = false; for (int i = 0; i < n; i++) @@ -675,33 +684,34 @@ namespace RustToDust.Ymir } else { - float baseDur = Math.Clamp(0.32f * MathF.Sqrt(MathF.Max(0.25f, geom.ModelHalfHeight * scale / 3.1456f)), 0.18f, 0.44f); + float hScale = MathF.Max(0.35f, geom.ModelHalfHeight * scale / 3.1456f); + float baseDur = Math.Clamp(0.46f * MathF.Sqrt(hScale), 0.26f, 0.68f); + float minDur = Math.Clamp((n == 4 ? 0.215f : 0.22f) * MathF.Sqrt(hScale), 0.14f, n == 4 ? 0.240f : 0.36f); float speedScale = Math.Clamp(horizSpeed / MathF.Max(6f, grid.Spec.MaxSpeed), 0f, 1f); float latDisturb = MathF.Abs((vel.X - desiredHorizVel.X) * right.X + (vel.Z - desiredHorizVel.Z) * right.Z); float effectiveDur = baseDur * (1f - 0.30f * speedScale); // Bound step duration across all legs so stance travel stays inside physical horizontal leg reach at speed - float sprintCrouch = n == 2 ? 0.06f * speedScale * scale : 0f; float speedForDur = MathF.Max(horizSpeed, desiredSpeed * 0.75f); if (speedForDur > 1.0f) { for (int i = 0; i < n; i++) { float actualDy = hipWorld[i].Y - (terrain.SampleHeight(hipWorld[i].X, hipWorld[i].Z) + geom.Legs[i].AnkleH * scale); - float nominalDy = MathF.Max(0.25f * scale, MathF.Max(actualDy, (rideHeight - sprintCrouch) + geom.Legs[i].HipInCom.Y * scale - geom.Legs[i].AnkleH * scale)); + float nominalDy = MathF.Max(0.25f * scale, MathF.Max(actualDy, rideHeight + geom.Legs[i].HipInCom.Y * scale - geom.Legs[i].AnkleH * scale)); float availReach = geom.Legs[i].MaxLegReach * scale; float maxHorizStride = MathF.Sqrt(MathF.Max(0.25f * scale * scale, availReach * availReach - nominalDy * nominalDy)); - effectiveDur = MathF.Min(effectiveDur, (0.68f * maxHorizStride) / speedForDur); + effectiveDur = MathF.Min(effectiveDur, (0.88f * maxHorizStride) / speedForDur); } } if (latDisturb > 1.1f) { effectiveDur = MathF.Min(effectiveDur, 0.20f); } - effectiveDur = Math.Clamp(effectiveDur, 0.105f, 0.44f); + effectiveDur = Math.Clamp(effectiveDur, minDur, 0.68f); ws.SwingTime += dt; - ws.SwingPhase += dt / MathF.Max(0.105f, effectiveDur); + ws.SwingPhase += dt / MathF.Max(minDur, effectiveDur); float u = ws.SwingPhase; // Bug 1 Fix: On u >= 1.0f, plant swinging group, flip _stanceGroup, IMMEDIATELY reset _swingTime = 0 & u = 0, @@ -814,10 +824,10 @@ namespace RustToDust.Ymir } accelFromRest = vAlong < vHDesLen * 0.5f; } - Vector2 stepOffset = vH * (effectiveDur * 0.50f) + vErr * kCapture; + Vector2 stepOffset = vH * (effectiveDur * 0.56f) + vErr * kCapture; if (accelFromRest) { - stepOffset += vHDes * (0.28f * effectiveDur); + stepOffset += vHDes * (0.36f * effectiveDur); float alongStep = Vector2.Dot(stepOffset, dirDes); if (alongStep < 0f) { @@ -924,7 +934,6 @@ namespace RustToDust.Ymir } // 4C: Pure Newtonian Centroidal GRF Wrench (ZERO magic hull springs or righting torques!) - Vector3 terrainNormal = WalkerState.SampleTerrainNormal(terrain, comPos.X, comPos.Z); float rawTerrainRateY = -(terrainNormal.X * vel.X + terrainNormal.Z * vel.Z) / MathF.Max(0.35f, terrainNormal.Y); float terrainRateY = Math.Clamp(rawTerrainRateY, -12f, 11f); float plantedYSum = 0f; @@ -937,7 +946,7 @@ namespace RustToDust.Ymir plantedYSum += ws.FootSole[i].Y; plantedYCount++; Vector3 footNorm = WalkerState.SampleTerrainNormal(terrain, ws.FootSole[i].X, ws.FootSole[i].Z); - if (footNorm.Y >= 0.78f && ws.FootSole[i].Y > uphillFootGroundY) + if (footNorm.Y >= 0.70f && ws.FootSole[i].Y > uphillFootGroundY) { uphillFootGroundY = ws.FootSole[i].Y; } @@ -946,7 +955,7 @@ namespace RustToDust.Ymir float supportGroundY = plantedYCount > 0 ? Math.Clamp(plantedYSum / plantedYCount, comGroundY - 0.03f * scale, comGroundY + 0.18f * scale) : comGroundY; - // Track rising traversable slopes (aheadNormal.Y >= 0.78) from planted uphill feet and forward probe ONLY during active movement + // Track rising traversable slopes (aheadNormal.Y >= 0.70) from planted uphill feet and forward probe ONLY during active movement float effectiveGroundY = MathF.Max(supportGroundY, comGroundY); float maxSpd = MathF.Max(4f, grid.Spec.MaxSpeed); bool activeMove = horizSpeed > 1.5f || desiredSpeed > 0.05f * maxSpd; @@ -968,7 +977,7 @@ namespace RustToDust.Ymir float ax = comPos.X + probeVec.X * leadDist; float az = comPos.Z + probeVec.Y * leadDist; Vector3 aheadNorm = WalkerState.SampleTerrainNormal(terrain, ax, az); - if (aheadNorm.Y >= 0.78f) + if (aheadNorm.Y >= 0.70f) { float aheadH = terrain.SampleHeight(ax, az); if (aheadH > slopeGroundY) @@ -978,10 +987,26 @@ namespace RustToDust.Ymir } if (slopeGroundY > comGroundY) { - float maxLift = n == 4 ? 0.35f * scale : 0.75f * scale; - float climbLift = MathF.Min(maxLift, (slopeGroundY - comGroundY) * 0.40f); + float maxLift = n == 4 ? 0.35f * scale : 0.90f * scale; + float liftFrac = n == 4 ? 0.40f : 0.50f; + float climbLift = MathF.Min(maxLift, (slopeGroundY - comGroundY) * liftFrac); effectiveGroundY = MathF.Max(effectiveGroundY, comGroundY + climbLift); } + if (n == 2 && view.Size2[lane] > 2.4f && terrainNormal.Y >= 0.78f) + { + float frontX = comPos.X + fwd.X * view.Size2[lane]; + float frontZ = comPos.Z + fwd.Z * view.Size2[lane]; + if (WalkerState.SampleTerrainNormal(terrain, frontX, frontZ).Y >= 0.78f) + { + float frontH = terrain.SampleHeight(frontX, frontZ); + Vector3 frontCornerRel = fwd * view.Size2[lane] - up * view.Size1[lane]; + float neededGroundY = (frontH + 0.18f * scale - frontCornerRel.Y) - rideHeight; + if (neededGroundY > effectiveGroundY) + { + effectiveGroundY = MathF.Min(comGroundY + 1.15f * scale, neededGroundY); + } + } + } } float targetY = effectiveGroundY + rideHeight; if (!activeMove && !ws.IsAirborne) @@ -1008,7 +1033,8 @@ namespace RustToDust.Ymir } if (!float.IsPositiveInfinity(maxLegComY)) { - targetY = MathF.Min(targetY, MathF.Max(comGroundY + geom.ModelHalfHeight * scale * 0.72f, maxLegComY)); + float minIdleRide = geom.ModelHalfHeight * scale * (n == 4 ? 0.72f : 0.80f); + targetY = MathF.Min(targetY, MathF.Max(comGroundY + minIdleRide, maxLegComY)); } } @@ -1016,10 +1042,14 @@ namespace RustToDust.Ymir mass * Gravity + mass * 48f * (targetY - comPos.Y) + mass * 10.5f * (terrainRateY - vel.Y)); - float penThresh = MathF.Min(geom.ModelHalfHeight * scale, rideHeight) - 0.01f * scale; + float penThresh = MathF.Min(view.Size1[lane], geom.ModelHalfHeight * scale * 0.72f); float hullBottomPen = (comGroundY + penThresh) - comPos.Y; float slopeMargin = activeMove ? 0.45f * scale : 0.02f * scale; - if (!ws.IsAirborne && terrainNormal.Y < 0.975f && (vel.Y - terrainRateY) < 0.4f && comPos.Y <= targetY + slopeMargin) + if (!ws.IsAirborne && activeMove && terrainNormal.Y < 0.99f && terrainNormal.Y >= 0.70f && (vel.Y - terrainRateY) < (n == 4 ? 2.5f : 0.6f) && comPos.Y <= targetY + 0.65f * scale) + { + fyDes = MathF.Max(fyDes, mass * Gravity * 1.10f); + } + else if (!ws.IsAirborne && terrainNormal.Y < 0.975f && (vel.Y - terrainRateY) < 0.4f && comPos.Y <= targetY + slopeMargin) { fyDes = MathF.Max(fyDes, mass * Gravity); } @@ -1029,16 +1059,19 @@ namespace RustToDust.Ymir Vector3 driveRight = right - terrainNormal * Vector3.Dot(right, terrainNormal); driveRight = driveRight.LengthSquared() > 1e-5f ? Vector3.Normalize(driveRight) : right; - // Steep-cliff strip (n.Y < 0.78 at COM or ahead on sprint path): prevent burrowing into Mesa cliff walls + // Steep-cliff strip (n.Y < 0.70 sustained ahead): prevent burrowing into vertical Mesa cliff walls without false braking on 1-pixel DEM creases Vector3 cliffNormal = terrainNormal; if (desiredSpeed > 0.1f) { Vector3 probeDir = Vector3.Normalize(new Vector3(desiredHorizVel.X, 0f, desiredHorizVel.Z)); - float baseProbe = MathF.Max(view.Size2[lane], geom.FootHalfL * scale) + 1.5f * scale; - float farProbe = baseProbe + horizSpeed * 0.45f; - foreach (float pd in new[] { baseProbe, (baseProbe + farProbe) * 0.5f, farProbe }) + float baseProbe = MathF.Max(view.Size2[lane], geom.FootHalfL * scale) + 0.8f * scale; + float lookProbe = baseProbe + 2.0f; + foreach (float pd in new[] { baseProbe, lookProbe }) { - Vector3 aheadN = WalkerState.SampleTerrainNormal(terrain, comPos.X + probeDir.X * pd, comPos.Z + probeDir.Z * pd); + Vector3 n1 = WalkerState.SampleTerrainNormal(terrain, comPos.X + probeDir.X * pd, comPos.Z + probeDir.Z * pd); + Vector3 n2 = WalkerState.SampleTerrainNormal(terrain, comPos.X + probeDir.X * (pd + 1.5f), comPos.Z + probeDir.Z * (pd + 1.5f)); + Vector3 nAvg = n1 + n2; + Vector3 aheadN = nAvg.LengthSquared() > 1e-5f ? Vector3.Normalize(nAvg) : Vector3.UnitY; if (aheadN.Y < cliffNormal.Y) { cliffNormal = aheadN; @@ -1046,8 +1079,11 @@ namespace RustToDust.Ymir } } Vector3 effectiveDriveVel = desiredHorizVel; - // Physical grade resistance: steep uphill climbs naturally slow stride speed (prevents ski-jumping off steep dune crests) - if (terrainNormal.Y < 0.96f && terrainNormal.Y >= 0.78f && desiredSpeed > 0.1f) + // Physical grade resistance: fast sprinters moderate uphill speed earlier (>22.3 deg) to avoid dune sky-launch, while 20 m/s siege walkers keep full climb torque up to 23.8 deg + float speedFactor = Math.Clamp((desiredSpeed - 20f) / 6f, 0f, 1f); + float gradeStartNy = 0.915f + 0.010f * speedFactor; + float gradeFloor = 0.42f - 0.04f * speedFactor; + if (terrainNormal.Y < gradeStartNy && terrainNormal.Y >= 0.70f && desiredSpeed > 0.1f) { Vector3 downhillHoriz = new(terrainNormal.X, 0f, terrainNormal.Z); float dhLen = downhillHoriz.Length(); @@ -1057,13 +1093,13 @@ namespace RustToDust.Ymir float uphillComp = -Vector3.Dot(effectiveDriveVel, downhillHoriz); if (uphillComp > 0f) { - float gradeScale = Math.Clamp((terrainNormal.Y - 0.76f) / 0.20f, 0.25f, 1.0f); + float gradeScale = Math.Clamp((terrainNormal.Y - 0.70f) / MathF.Max(0.05f, gradeStartNy - 0.70f), gradeFloor, 1.0f); effectiveDriveVel += downhillHoriz * (uphillComp * (1f - gradeScale)); } } } Vector3 cliffHoriz = Vector3.Zero; - bool onSteepCliff = cliffNormal.Y < 0.78f; + bool onSteepCliff = cliffNormal.Y < 0.70f; if (onSteepCliff) { cliffHoriz = new Vector3(cliffNormal.X, 0f, cliffNormal.Z); @@ -1083,18 +1119,23 @@ namespace RustToDust.Ymir float latGain = mass * 8.5f * avgIntegrity; if (idleCmd) { - float stopGain = mass * 16f * avgIntegrity; + float stopGain = mass * 30f * avgIntegrity; driveGain = MathF.Max(driveGain, stopGain); latGain = MathF.Max(latGain, stopGain); } + Vector3 fwdFlat = new(driveFwd.X, 0f, driveFwd.Z); + fwdFlat = fwdFlat.LengthSquared() > 1e-5f ? Vector3.Normalize(fwdFlat) : fwd; + Vector3 rightFlat = new(driveRight.X, 0f, driveRight.Z); + rightFlat = rightFlat.LengthSquared() > 1e-5f ? Vector3.Normalize(rightFlat) : right; + float fwdVel = Vector3.Dot(vel, driveFwd); - float fwdDes = Vector3.Dot(effectiveDriveVel, new Vector3(driveFwd.X, 0f, driveFwd.Z)); + float fwdDes = Vector3.Dot(effectiveDriveVel, fwdFlat); float latVel = Vector3.Dot(vel, driveRight); - float latDes = Vector3.Dot(effectiveDriveVel, new Vector3(driveRight.X, 0f, driveRight.Z)); + float latDes = Vector3.Dot(effectiveDriveVel, rightFlat); Vector3 horizDriveForce = - new Vector3(driveFwd.X, 0f, driveFwd.Z) * ((fwdDes - fwdVel) * driveGain) + - new Vector3(driveRight.X, 0f, driveRight.Z) * ((latDes - latVel) * latGain); + fwdFlat * ((fwdDes - fwdVel) * driveGain) + + rightFlat * ((latDes - latVel) * latGain); float hx = view.Size0[lane]; float hy = MathF.Max(view.Size1[lane], geom.ModelHalfHeight * scale); @@ -1174,8 +1215,8 @@ namespace RustToDust.Ymir } desiredUp = Vector3.Normalize(desiredUp + fwd * (accelPitch + limpFwdLean) - right * limpLatLean + driveBank); - // Cap desiredUp tilt: bipeds <= 8.6 deg, quadrupeds <= 20.1 deg (matches 15-22 deg slopes while staying inside 22 deg Mesa upright margin) - float maxDesiredTiltRad = n == 4 ? 0.350f : 0.150f; + // Cap desiredUp tilt: bipeds <= 8.6 deg, arachnid quadruped <= 14.6 deg, siege quadruped <= 18.3 deg + float maxDesiredTiltRad = n == 4 ? (geom.IsArachnidUp ? 0.255f : 0.320f) : 0.150f; float dotUp = Math.Clamp(desiredUp.Y, -1f, 1f); if (MathF.Acos(dotUp) > maxDesiredTiltRad) { @@ -1187,10 +1228,11 @@ namespace RustToDust.Ymir } Vector3 tiltAxis = Vector3.Cross(up, desiredUp); + float yawGain = MathF.Abs(targetYawVel) < 1e-3f ? 48f : 22f; Vector3 torqueDes = new( - iTilt * (tiltAxis.X * 72f - angVel.X * 14f), - iy * (targetYawVel - angVel.Y) * 8.5f, - iTilt * (tiltAxis.Z * 72f - angVel.Z * 14f)); + iTilt * (tiltAxis.X * 95f - angVel.X * 22f), + iy * (targetYawVel - angVel.Y) * yawGain, + iTilt * (tiltAxis.Z * 95f - angVel.Z * 22f)); // Allocate strictly across planted feet inside reach Span weight = stackalloc float[4]; @@ -1341,7 +1383,7 @@ namespace RustToDust.Ymir fz += (-relX / sumRelR2) * torqueDes.Y * sharedYawScale; } - // Coulomb friction cone clamp: |F_horiz| <= 0.85 * fy + // Coulomb friction cone clamp: |F_horiz| <= Mu * fy float maxHoriz = Mu * fy; float hMag = MathF.Sqrt(fx * fx + fz * fz); if (hMag > maxHoriz && hMag > 1e-4f) @@ -1435,11 +1477,13 @@ namespace RustToDust.Ymir float stanceIntegrity = totalForce.Y > 1e-3f ? weightedIntegSum / totalForce.Y : avgIntegrity; Vector3 tRes = torqueDes - tContact; float resHorizMag = MathF.Sqrt(tRes.X * tRes.X + tRes.Z * tRes.Z); - float maxHipAttitudeTorque = iTilt * 28f * supportFrac * stanceIntegrity; + float maxHipAttitudeTorque = iTilt * 44f * supportFrac * stanceIntegrity; float attScale = resHorizMag > maxHipAttitudeTorque && resHorizMag > 1e-4f ? maxHipAttitudeTorque / resHorizMag : 1f; - totalTorque = tContact + new Vector3(tRes.X * attScale, 0f, tRes.Z * attScale); + float maxHipYawTorque = iy * 200f * supportFrac * stanceIntegrity; + float resYaw = Math.Clamp(tRes.Y, -maxHipYawTorque, maxHipYawTorque); + totalTorque = tContact + new Vector3(tRes.X * attScale, resYaw, tRes.Z * attScale); } // Predictive inelastic ground contact (triggers ONLY on high-speed dune/cliff slam or deep penetration, never gentle stride ripples) @@ -1450,7 +1494,7 @@ namespace RustToDust.Ymir { Vector3 contactNorm = WalkerState.SampleTerrainNormal(terrain, comPos.X + vel.X * dt, comPos.Z + vel.Z * dt); float vInto = Vector3.Dot(vel, contactNorm); - if (vInto < -2.0f || hullBottomPen > 0.12f) + if (effectivePen > 0.02f && (vInto < -5.5f || hullBottomPen > 0.25f)) { float penVel = MathF.Min(MathF.Max(0f, hullBottomPen) / dt, 4.0f); float neededDvN = MathF.Max(0f, -vInto) + penVel; @@ -1486,11 +1530,11 @@ namespace RustToDust.Ymir float subDt = dt * 0.5f; float limbI = MathF.Max(1f, mass * scale * scale * 0.025f); float kpStance = limbI * 1400f; - float kpSwing = limbI * 420f; + float kpSwing = limbI * 950f; float kdStance = limbI * (2f * 0.88f * MathF.Sqrt(1400f)); - float kdSwing = limbI * (2f * 0.88f * MathF.Sqrt(420f)); - float tauLimitBase = limbI * 460f; - float tauLimitAnkle = limbI * 340f; + float kdSwing = limbI * (2f * 0.85f * MathF.Sqrt(950f)); + float tauLimitBase = limbI * 850f; + float tauLimitAnkle = limbI * 520f; for (int i = 0; i < n; i++) { diff --git a/tests/RustToDust.Tests/HybridBWalkerTests.cs b/tests/RustToDust.Tests/HybridBWalkerTests.cs index 9dd4a9e..9099c55 100644 --- a/tests/RustToDust.Tests/HybridBWalkerTests.cs +++ b/tests/RustToDust.Tests/HybridBWalkerTests.cs @@ -5,6 +5,7 @@ using RustToDust.Core; using RustToDust.Ymir; using Xunit; using Xunit.Abstractions; +using Ymir.Box3D; namespace RustToDust.Tests { @@ -1051,5 +1052,386 @@ namespace RustToDust.Tests Assert.True(maxRelCom <= modelRide + 0.25f, $"Bastion idle COM floated too high: {maxRelCom:F3}m > {modelRide + 0.25f:F3}m"); Assert.True(maxReachOverflow <= 0.05f, $"Bastion idle leg hyper-extended past MaxLegReach by {maxReachOverflow:F4}m > 0.05m"); } + + private static (TerrainField Terrain, float[] Heights, int GridRes, float CellSize, float MinY, float MaxY) MakeSyntheticSlope(float slopeDeg) + { + const float sizeMeters = 400f; + const int gridRes = 201; + const float cellSize = sizeMeters / (gridRes - 1); + float half = sizeMeters * 0.5f; + float tan = MathF.Tan(slopeDeg * MathF.PI / 180f); + var heights = new float[gridRes * gridRes]; + for (int iz = 0; iz < gridRes; iz++) + { + float z = -half + iz * cellSize; + float h = (z + half) * tan; + int row = iz * gridRes; + for (int ix = 0; ix < gridRes; ix++) + { + heights[row + ix] = h; + } + } + float minY = -10f; + float maxY = sizeMeters * tan + 10f; + var terrain = TerrainField.LoadHeightmap(sizeMeters, gridRes, heights, minY, maxY, seed: 1UL); + return (terrain, heights, gridRes, cellSize, minY, maxY); + } + + private static (Box3DSoaWorld World, Box3DSoaBodyHandle Body, WalkerState Walker, ChassisGrid Grid) SpawnWalkerOnSyntheticTerrain( + ChassisSpec spec, + in (TerrainField Terrain, float[] Heights, int GridRes, float CellSize, float MinY, float MaxY) syn, + float startX, + float startZ) + { + var world = new Box3DSoaWorld(capacity: 8, gravityX: 0f, gravityY: -20f, gravityZ: 0f); + float half = syn.Terrain.MapHalfExtent; + world.AddStaticHeightField( + 1UL, + (-half, 0f, -half), + syn.Heights, + syn.GridRes, + syn.GridRes, + (syn.CellSize, 1.0f, syn.CellSize), + syn.MinY, + syn.MaxY, + friction: 0.15f, + restitution: 0.0f); + + float physHalfH = ArenaSession.GetPhysicsHalfHeight(spec); + float volume = 8f * spec.HalfWidth * physHalfH * spec.HalfLength; + float density = spec.MassKg / MathF.Max(0.1f, volume); + Quaternion q0 = Quaternion.Identity; + if (spec.Plane == GridPlane.Dorsal) + { + var (nx, ny, nz) = syn.Terrain.SampleNormal(startX, startZ); + Vector3 desUp = Vector3.Normalize(Vector3.Lerp(Vector3.UnitY, new Vector3(nx, ny, nz), 0.90f)); + Vector3 axis = Vector3.Cross(Vector3.UnitY, desUp); + if (axis.LengthSquared() > 1e-8f) + { + float ang = MathF.Min(0.295f, MathF.Acos(Math.Clamp(desUp.Y, -1f, 1f))); + q0 = Quaternion.Normalize(Quaternion.CreateFromAxisAngle(Vector3.Normalize(axis), ang)); + } + } + float spawnY = syn.Terrain.SampleHeight(startX, startZ) + WalkerLocomotion.GetRideHeight(spec); + var body = world.AddBox( + 1000UL, + (startX, spawnY, startZ), + (spec.HalfWidth, physHalfH, spec.HalfLength), + density, + (q0.X, q0.Y, q0.Z, q0.W), + friction: 0.2f, + restitution: 0.1f); + + var grid = new ChassisGrid(spec); + var ws = new WalkerState(spec); + ws.InitializePose(new Vector3(startX, spawnY, startZ), q0, world.View.Mass[body.Lane], syn.Terrain); + return (world, body, ws, grid); + } + + [Fact] + public void HybridB_All7Mechs_BoldWeightedStrides_NoTinyBabySteps() + { + var specs = new[] + { + Catalog.Breaker, + Catalog.Paladin, + Catalog.Raptor, + Catalog.Spectre, + Catalog.Kestrel, + Catalog.Manticore, + Catalog.Bastion + }; + var flat = MakeSyntheticSlope(0f); + + foreach (var spec in specs) + { + var (world, body, ws, grid) = SpawnWalkerOnSyntheticTerrain(spec, flat, 0f, -140f); + using (world) + { + int lane = body.Lane; + var view = world.View; + int nLegs = ws.Geom.LegCount; + var prevPlanted = new bool[nLegs]; + var lastPlantTime = new float[nLegs]; + for (int i = 0; i < nLegs; i++) + { + prevPlanted[i] = ws.Planted[i]; + lastPlantTime[i] = -1f; + } + + var minHipPitch = new float[nLegs]; + var maxHipPitch = new float[nLegs]; + Array.Fill(minHipPitch, float.PositiveInfinity); + Array.Fill(maxHipPitch, float.NegativeInfinity); + + double stepDurSum = 0.0; + int stepDurCount = 0; + double footSepSum = 0.0; + double swingTravelSum = 0.0; + int strideCount = 0; + + for (int t = 0; t < 180; t++) + { + var pos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]); + var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]); + var vel = new Vector3(view.VelocityX[lane], view.VelocityY[lane], view.VelocityZ[lane]); + var angVel = new Vector3(view.AngularVelocityX[lane], view.AngularVelocityY[lane], view.AngularVelocityZ[lane]); + + WalkerLocomotion.StepWalker( + ws, grid, flat.Terrain, view, lane, view.Mass[lane], + pos, q, vel, angVel, + new Vector3(0f, 0f, grid.Spec.MaxSpeed), 0f, false, ArenaSession.FixedDt); + world.Step(ArenaSession.FixedDt, ArenaSession.SubStepCount); + + if (t >= 60) + { + for (int i = 0; i < nLegs; i++) + { + float hp = ws.Actuators[i].Theta.HipPitch; + if (hp < minHipPitch[i]) minHipPitch[i] = hp; + if (hp > maxHipPitch[i]) maxHipPitch[i] = hp; + + bool curPlanted = ws.Planted[i]; + if (!prevPlanted[i] && curPlanted) + { + if (lastPlantTime[i] >= 0f) + { + float cycleSec = ws.SimTime - lastPlantTime[i]; + stepDurSum += cycleSec * 0.5f; + stepDurCount++; + } + lastPlantTime[i] = ws.SimTime; + + int partner = i ^ 1; + float foreAftSep = MathF.Abs(ws.FootSole[i].Z - ws.FootSole[partner].Z); + float swingTravel = Vector2.Distance( + new Vector2(ws.SwingTargetSole[i].X, ws.SwingTargetSole[i].Z), + new Vector2(ws.SwingStartSole[i].X, ws.SwingStartSole[i].Z)); + footSepSum += foreAftSep; + swingTravelSum += swingTravel; + strideCount++; + } + prevPlanted[i] = curPlanted; + } + } + else + { + for (int i = 0; i < nLegs; i++) + { + prevPlanted[i] = ws.Planted[i]; + } + } + } + + Assert.True(stepDurCount >= 2, $"{spec.Id}: expected >= 2 measured step intervals, got {stepDurCount}"); + Assert.True(strideCount >= 2, $"{spec.Id}: expected >= 2 measured strides, got {strideCount}"); + float avgStepDur = (float)(stepDurSum / stepDurCount); + float avgFootSep = (float)(footSepSum / strideCount); + float avgSwingTravel = (float)(swingTravelSum / strideCount); + float maxHipSwingRad = 0f; + for (int i = 0; i < nLegs; i++) + { + maxHipSwingRad = MathF.Max(maxHipSwingRad, maxHipPitch[i] - minHipPitch[i]); + } + + bool isCompact = spec.Id == "breaker" || spec.Id == "manticore"; + float minFootSep = isCompact ? 1.25f : 1.80f; + + _output.WriteLine( + $"{spec.Id,-10} stepDur={avgStepDur:F3}s ({1f / avgStepDur:F2} Hz) footToFoot={avgFootSep:F2}m " + + $"swingTravel={avgSwingTravel:F2}m hipPitchP2P={maxHipSwingRad:F3}rad ({maxHipSwingRad * 180f / MathF.PI:F1}deg)"); + + Assert.True(avgStepDur >= 0.21f, + $"{spec.Id}: tiny baby-step cadence {avgStepDur:F3}s < 0.21s"); + Assert.True(avgFootSep >= minFootSep, + $"{spec.Id}: foot-to-foot stride {avgFootSep:F2}m < {minFootSep:F2}m"); + Assert.True(maxHipSwingRad >= 0.45f, + $"{spec.Id}: insufficient hip-pitch actuator swing {maxHipSwingRad:F3} rad < 0.45 rad"); + } + } + } + + [Fact] + public void HybridB_All7Mechs_ClimbSmallAndMediumSlopes_6To22Deg_NeverDefeated() + { + var specs = new[] + { + Catalog.Breaker, + Catalog.Paladin, + Catalog.Raptor, + Catalog.Spectre, + Catalog.Kestrel, + Catalog.Manticore, + Catalog.Bastion + }; + float[] slopesDeg = { 6f, 12f, 18f, 22f }; + var flat = MakeSyntheticSlope(0f); + var slopeTerrains = new (float Deg, (TerrainField Terrain, float[] Heights, int GridRes, float CellSize, float MinY, float MaxY) Syn)[slopesDeg.Length]; + for (int s = 0; s < slopesDeg.Length; s++) + { + slopeTerrains[s] = (slopesDeg[s], MakeSyntheticSlope(slopesDeg[s])); + } + + foreach (var spec in specs) + { + float flatSpeed; + { + var (world, body, ws, grid) = SpawnWalkerOnSyntheticTerrain(spec, flat, 0f, -140f); + using (world) + { + int lane = body.Lane; + var view = world.View; + for (int t = 0; t < 150; t++) + { + var pos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]); + var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]); + var vel = new Vector3(view.VelocityX[lane], view.VelocityY[lane], view.VelocityZ[lane]); + var angVel = new Vector3(view.AngularVelocityX[lane], view.AngularVelocityY[lane], view.AngularVelocityZ[lane]); + WalkerLocomotion.StepWalker( + ws, grid, flat.Terrain, view, lane, view.Mass[lane], + pos, q, vel, angVel, + new Vector3(0f, 0f, grid.Spec.MaxSpeed), 0f, false, ArenaSession.FixedDt); + world.Step(ArenaSession.FixedDt, ArenaSession.SubStepCount); + } + flatSpeed = MathF.Sqrt(view.VelocityX[lane] * view.VelocityX[lane] + view.VelocityZ[lane] * view.VelocityZ[lane]); + } + } + + var summary = $"{spec.Id,-10} flat={flatSpeed:F2}m/s"; + foreach (var (deg, syn) in slopeTerrains) + { + var (world, body, ws, grid) = SpawnWalkerOnSyntheticTerrain(spec, syn, 0f, -140f); + using (world) + { + int lane = body.Lane; + var view = world.View; + float gStart = syn.Terrain.SampleHeight(0f, -140f); + float minSpeedAfterAccel = float.PositiveInfinity; + + for (int t = 0; t < 150; t++) + { + var pos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]); + var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]); + var vel = new Vector3(view.VelocityX[lane], view.VelocityY[lane], view.VelocityZ[lane]); + var angVel = new Vector3(view.AngularVelocityX[lane], view.AngularVelocityY[lane], view.AngularVelocityZ[lane]); + WalkerLocomotion.StepWalker( + ws, grid, syn.Terrain, view, lane, view.Mass[lane], + pos, q, vel, angVel, + new Vector3(0f, 0f, grid.Spec.MaxSpeed), 0f, false, ArenaSession.FixedDt); + world.Step(ArenaSession.FixedDt, ArenaSession.SubStepCount); + + if (t >= 30) + { + float fwdSpd = view.VelocityZ[lane]; + if (fwdSpd < minSpeedAfterAccel) minSpeedAfterAccel = fwdSpd; + } + } + + float endZ = view.PositionZ[lane]; + float endHorizSpeed = MathF.Sqrt(view.VelocityX[lane] * view.VelocityX[lane] + view.VelocityZ[lane] * view.VelocityZ[lane]); + float gEnd = syn.Terrain.SampleHeight(view.PositionX[lane], endZ); + float climbM = gEnd - gStart; + float dispM = endZ - (-140f); + float ratio = endHorizSpeed / MathF.Max(1f, flatSpeed); + float reqRatio = deg <= 12f ? 0.60f : 0.45f; + + summary += $" | {deg:F0}deg:{endHorizSpeed:F1}m/s({ratio * 100f:F0}%,+{climbM:F1}m,min={minSpeedAfterAccel:F1})"; + + Assert.True(dispM > 12f && climbM > 1.2f, + $"{spec.Id} @ {deg}deg: failed climb (disp={dispM:F2}m, climb={climbM:F2}m)"); + Assert.True(minSpeedAfterAccel > 4.0f, + $"{spec.Id} @ {deg}deg: stalled or kicked back (minFwdSpd={minSpeedAfterAccel:F2}m/s)"); + Assert.True(ratio >= reqRatio, + $"{spec.Id} @ {deg}deg: speed {endHorizSpeed:F2}m/s ({ratio * 100f:F1}% of flat {flatSpeed:F2}) < {reqRatio * 100f:F0}%"); + } + } + _output.WriteLine(summary); + } + } + + [Fact] + public void HybridB_All7Mechs_YawRelease_StopsCrisplyWithMinimalCoast() + { + var specs = new[] + { + Catalog.Breaker, + Catalog.Paladin, + Catalog.Raptor, + Catalog.Spectre, + Catalog.Kestrel, + Catalog.Manticore, + Catalog.Bastion + }; + + foreach (var spec in specs) + { + using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true); + for (int i = 1; i < session.State.Contenders.Count; i++) + { + session.SetContenderPose(i, 500f + i * 16f, 500f); + } + + session.SetContenderPose(0, 0f, 0f, 0f); + session.State.SpawnChassisDrop(0f, 0f, spec); + Assert.True(session.TrySwapNearbyChassis(0), $"Failed swap to {spec.Id}"); + session.SetContenderPose(0, 0f, 0f, 0f); + var player = session.State.Contenders[0]; + int lane = session.GetContenderBody(player.Id)!.Value.Lane; + + // Spin 1.0s at full steer + for (int t = 0; t < 60; t++) + { + session.SetHumanInput(0, new PlayerInput( + Throttle: 0f, + Steer: 1.0f, + AimWorldX: 0f, + AimWorldZ: 50f, + Fire: false, + InteractPickup: false, + Brake: false)); + session.Step(); + } + + float yawAtRelease = player.Yaw; + float spinAngVelY = session.World.View.AngularVelocityY[lane]; + float maxOvershootRad = 0f; + float angVelAt020s = 0f; + + // Release for 0.5s (30 ticks) + for (int t = 0; t < 30; t++) + { + session.SetHumanInput(0, new PlayerInput( + Throttle: 0f, + Steer: 0f, + AimWorldX: 0f, + AimWorldZ: 50f, + Fire: false, + InteractPickup: false, + Brake: false)); + session.Step(); + + float overshoot = MathF.Abs(MatchRules.NormalizeAngle(player.Yaw - yawAtRelease)); + if (overshoot > maxOvershootRad) + { + maxOvershootRad = overshoot; + } + if (t == 11) + { + angVelAt020s = session.World.View.AngularVelocityY[lane]; + } + } + + _output.WriteLine( + $"{spec.Id,-10} spinOmegaY={spinAngVelY:F2}rad/s overshoot={maxOvershootRad:F4}rad ({maxOvershootRad * 180f / MathF.PI:F2}deg) " + + $"omegaY@0.20s={angVelAt020s:F4}rad/s"); + + Assert.True(MathF.Abs(spinAngVelY) > 1.0f, + $"{spec.Id}: failed to spin up before release (omegaY={spinAngVelY:F2})"); + Assert.True(maxOvershootRad <= 0.08f, + $"{spec.Id}: yaw coast overshoot {maxOvershootRad:F4} rad ({maxOvershootRad * 180f / MathF.PI:F2} deg) > 0.08 rad"); + Assert.True(MathF.Abs(angVelAt020s) <= 0.05f, + $"{spec.Id}: residual yaw angVel@0.20s={angVelAt020s:F4} rad/s > 0.05 rad/s"); + } + } } } diff --git a/tests/RustToDust.Tests/TerrainTests.cs b/tests/RustToDust.Tests/TerrainTests.cs index 79c9479..4ba9ea8 100644 --- a/tests/RustToDust.Tests/TerrainTests.cs +++ b/tests/RustToDust.Tests/TerrainTests.cs @@ -373,11 +373,15 @@ namespace RustToDust.Tests Assert.False(float.IsNaN(up.Y), $"NaN orientation at tick {tick}"); float gh = session.State.Terrain.SampleHeight(player.X, player.Z); - float bottomRel = (player.Y - player.Grid.Spec.HalfHeight) - gh; + float hullHalfH = player.Grid.Spec.IsWalker + ? ArenaSession.GetPhysicsHalfHeight(player.Grid.Spec) + : player.Grid.Spec.HalfHeight; + float bottomRel = (player.Y - hullHalfH) - gh; + float airGapRel = (player.Y - player.Grid.Spec.HalfHeight) - gh; maxGroundY = MathF.Max(maxGroundY, gh); minBottomRel = MathF.Min(minBottomRel, bottomRel); - maxAirGap = MathF.Max(maxAirGap, bottomRel); + maxAirGap = MathF.Max(maxAirGap, airGapRel); minUpDot = MathF.Min(minUpDot, up.Y); }