Fix Cut 5b Soul Pass #2: Dorsal hitbox, quadruped slope alignment, idle leg probe, and camera occlusion

This commit is contained in:
Meta Vens 2026-12-05 07:42:48 +01:00
commit 8eba2ea39f
4 changed files with 387 additions and 34 deletions

View file

@ -710,6 +710,12 @@ public partial class Main : Node3D
Vector3 camPos = shoulderPos - lookDir * effectiveBack;
float minTerrainY = Session.State.Terrain.SampleHeight(camPos.X, camPos.Z) + 1.2f;
if (camPos.Y < minTerrainY)
{
camPos.Y = minTerrainY;
}
// Segment 3: verify direct pivot -> camPos LOS against static terrain/buildings so stepped wings cannot occlude player
Vector3 pivotToCam = camPos - pivot;
float pivotToCamDist = pivotToCam.Length();
@ -722,18 +728,12 @@ public partial class Main : Node3D
}
}
float minTerrainY = Session.State.Terrain.SampleHeight(camPos.X, camPos.Z) + 1.2f;
if (camPos.Y < minTerrainY)
{
camPos.Y = minTerrainY;
}
_camera.GlobalPosition = camPos;
_camera.LookAt(camPos + lookDir * 60f, Vector3.Up);
}
private static float SafeCameraPullbackDist(float rawDist) =>
MathF.Max(MathF.Min(0.05f, rawDist * 0.85f), MathF.Min(rawDist - 0.35f, rawDist * 0.85f));
MathF.Max(0.0f, rawDist - MathF.Min(0.35f, MathF.Max(0.08f, rawDist * 0.25f)));
private bool CastStaticCameraRay(Vector3 origin, Vector3 dir, float maxDist, out float hitDist)
{

View file

@ -525,7 +525,7 @@ namespace RustToDust.Ymir
private static float GetPhysicsHalfHeight(ChassisSpec spec) =>
spec.IsWalker
? spec.HalfHeight * (spec.Plane == GridPlane.Dorsal ? 0.42f : 0.72f)
? spec.HalfHeight * (spec.Plane == GridPlane.Dorsal ? 0.62f : 0.72f)
: spec.HalfHeight;
private void SpawnContenderBody(ContenderState c)
@ -540,6 +540,33 @@ namespace RustToDust.Ymir
? Math.Clamp(c.TargetHoverAltAgl, MatchRules.VtolMinClearanceAgl, MathF.Max(MatchRules.VtolMinClearanceAgl, spec.HoverMaxAltitudeM))
: 0.15f;
float spawnY = State.Terrain.SampleHeight(c.X, c.Z) + spec.HalfHeight + clearance;
if (spec.IsWalker && spec.Plane == GridPlane.Dorsal)
{
var (nx, ny, nz) = State.Terrain.SampleNormal(c.X, c.Z);
Vector3 centerNorm = new Vector3(nx, ny, nz);
centerNorm = centerNorm.LengthSquared() > 1e-6f ? Vector3.Normalize(centerNorm) : Vector3.UnitY;
Vector3 fwd = Vector3.Transform(Vector3.UnitZ, q);
fwd.Y = 0f;
fwd = fwd.LengthSquared() > 1e-5f ? Vector3.Normalize(fwd) : Vector3.UnitZ;
Vector3 right = Vector3.Cross(fwd, Vector3.UnitY);
Vector3 hullSlope = WalkerLocomotion.ComputeHullSlopeNormal(State.Terrain, c.X, c.Z, fwd, right, spec.HalfWidth, spec.HalfLength, centerNorm, out _);
q = WalkerLocomotion.AlignUpToSlope(q, hullSlope, 0.90f, 0.350f);
float minCornerClr = float.PositiveInfinity;
foreach (float sx in new[] { -spec.HalfWidth, spec.HalfWidth })
{
foreach (float sz in new[] { -spec.HalfLength, spec.HalfLength })
{
Vector3 corner = new Vector3(c.X, spawnY, c.Z) + Vector3.Transform(new Vector3(sx, -physHalfH, sz), q);
float clr = corner.Y - State.Terrain.SampleHeight(corner.X, corner.Z);
if (clr < minCornerClr) minCornerClr = clr;
}
}
if (minCornerClr < 0.25f)
{
spawnY += MathF.Min(1.2f, 0.25f - minCornerClr);
}
}
c.Y = spawnY;
var handle = _world.AddBox(

View file

@ -445,6 +445,81 @@ namespace RustToDust.Ymir
return geom.ModelRideHeight * scale;
}
internal static Vector3 ComputeHullSlopeNormal(
TerrainField terrain,
float x,
float z,
Vector3 fwd,
Vector3 right,
float halfW,
float halfL,
Vector3 centerNormal,
out float planeCenterY)
{
float w = MathF.Max(1.0f, halfW * 0.90f);
float l = MathF.Max(1.0f, halfL * 0.90f);
float flX = x - right.X * w + fwd.X * l, flZ = z - right.Z * w + fwd.Z * l;
float frX = x + right.X * w + fwd.X * l, frZ = z + right.Z * w + fwd.Z * l;
float rlX = x - right.X * w - fwd.X * l, rlZ = z - right.Z * w - fwd.Z * l;
float rrX = x + right.X * w - fwd.X * l, rrZ = z + right.Z * w - fwd.Z * l;
float hCenter = terrain.SampleHeight(x, z);
if (terrain.SampleNormal(flX, flZ).Ny < 0.72f ||
terrain.SampleNormal(frX, frZ).Ny < 0.72f ||
terrain.SampleNormal(rlX, rlZ).Ny < 0.72f ||
terrain.SampleNormal(rrX, rrZ).Ny < 0.72f)
{
planeCenterY = hCenter;
return centerNormal.Y >= 0.78f ? centerNormal : Vector3.UnitY;
}
float hFL = terrain.SampleHeight(flX, flZ);
float hFR = terrain.SampleHeight(frX, frZ);
float hRL = terrain.SampleHeight(rlX, rlZ);
float hRR = terrain.SampleHeight(rrX, rrZ);
planeCenterY = 0.25f * (hFL + hFR + hRL + hRR);
float gf = ((hFR + hFL) - (hRR + hRL)) / (4f * l);
float gr = ((hFR + hRR) - (hFL + hRL)) / (4f * w);
Vector3 nPlane = Vector3.Normalize(Vector3.UnitY - fwd * gf - right * gr);
if (nPlane.Y < 0.75f)
{
return centerNormal.Y >= 0.78f ? centerNormal : Vector3.UnitY;
}
return centerNormal.Y >= 0.78f
? Vector3.Normalize(centerNormal * 0.30f + nPlane * 0.70f)
: nPlane;
}
internal static Quaternion AlignUpToSlope(Quaternion yawQuat, Vector3 slopeNormal, float alignFraction, float maxTiltRad)
{
Vector3 fwd = Vector3.Transform(Vector3.UnitZ, yawQuat);
fwd.Y = 0f;
fwd = fwd.LengthSquared() > 1e-5f ? Vector3.Normalize(fwd) : Vector3.UnitZ;
Vector3 right = Vector3.Cross(fwd, Vector3.UnitY);
float slopePitch = MathF.Asin(Math.Clamp(Vector3.Dot(fwd, slopeNormal), -0.45f, 0.45f)) * alignFraction;
float slopeRoll = MathF.Asin(Math.Clamp(Vector3.Dot(right, slopeNormal), -0.40f, 0.40f)) * alignFraction;
Vector3 desUp = Vector3.Normalize(Vector3.UnitY + fwd * MathF.Sin(slopePitch) + right * MathF.Sin(slopeRoll));
if (MathF.Acos(Math.Clamp(desUp.Y, -1f, 1f)) > maxTiltRad)
{
Vector3 h = new(desUp.X, 0f, desUp.Z);
float hLen = h.Length();
desUp = hLen > 1e-4f
? Vector3.UnitY * MathF.Cos(maxTiltRad) + (h / hLen) * MathF.Sin(maxTiltRad)
: Vector3.UnitY;
}
Vector3 axis = Vector3.Cross(Vector3.UnitY, desUp);
float axisLen = axis.Length();
if (axisLen <= 1e-5f)
{
return yawQuat;
}
float ang = MathF.Acos(Math.Clamp(desUp.Y, -1f, 1f));
return Quaternion.Normalize(Quaternion.CreateFromAxisAngle(axis / axisLen, ang) * yawQuat);
}
public static void StepWalker(
WalkerState ws,
ChassisGrid grid,
@ -859,32 +934,71 @@ 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 so wide/heavy hulls raise cleanly over hills
// Track rising traversable slopes (aheadNormal.Y >= 0.78) from planted uphill feet and forward probe ONLY during active movement
float effectiveGroundY = MathF.Max(supportGroundY, comGroundY);
float slopeGroundY = uphillFootGroundY;
Vector2 probeVec = horizSpeed > 1.0f
? new Vector2(vel.X / horizSpeed, vel.Z / horizSpeed)
: (desiredSpeed > 0.1f
? new Vector2(desiredHorizVel.X / desiredSpeed, desiredHorizVel.Z / desiredSpeed)
: new Vector2(fwd.X, fwd.Z));
float leadDist = Math.Clamp(MathF.Max(horizSpeed * 0.08f, view.Size2[lane] * 0.65f), 1.5f, 5.5f);
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)
float maxSpd = MathF.Max(4f, grid.Spec.MaxSpeed);
bool activeMove = horizSpeed > 1.5f || desiredSpeed > 0.05f * maxSpd;
float hullPlaneCenterY = comGroundY;
Vector3 hullSlopeNormal = n == 4
? ComputeHullSlopeNormal(terrain, comPos.X, comPos.Z, fwd, right, view.Size0[lane], view.Size2[lane], terrainNormal, out hullPlaneCenterY)
: terrainNormal;
if (activeMove)
{
float aheadH = terrain.SampleHeight(ax, az);
if (aheadH > slopeGroundY)
float slopeGroundY = uphillFootGroundY;
if (n == 4 && hullPlaneCenterY > slopeGroundY)
{
slopeGroundY = aheadH;
slopeGroundY = hullPlaneCenterY;
}
Vector2 probeVec = horizSpeed > 1.0f
? new Vector2(vel.X / horizSpeed, vel.Z / horizSpeed)
: new Vector2(desiredHorizVel.X / desiredSpeed, desiredHorizVel.Z / desiredSpeed);
float leadDist = Math.Clamp(MathF.Max(horizSpeed * 0.08f, view.Size2[lane] * 0.65f), 1.5f, 5.5f);
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)
{
float aheadH = terrain.SampleHeight(ax, az);
if (aheadH > slopeGroundY)
{
slopeGroundY = aheadH;
}
}
if (slopeGroundY > comGroundY)
{
float maxLift = n == 4 ? 0.35f * scale : 0.75f * scale;
float climbLift = MathF.Min(maxLift, (slopeGroundY - comGroundY) * 0.40f);
effectiveGroundY = MathF.Max(effectiveGroundY, comGroundY + climbLift);
}
}
if (slopeGroundY > comGroundY)
{
float climbLift = MathF.Min(0.75f * scale, (slopeGroundY - comGroundY) * 0.45f);
effectiveGroundY = MathF.Max(effectiveGroundY, comGroundY + climbLift);
}
float targetY = effectiveGroundY + rideHeight;
if (!activeMove && !ws.IsAirborne)
{
float maxLegComY = float.PositiveInfinity;
for (int i = 0; i < n; i++)
{
if (!ws.Planted[i])
{
continue;
}
Vector3 ankle = ws.FootSole[i] + ws.FootNormal[i] * (geom.Legs[i].AnkleH * scale);
Vector3 hipOff = Vector3.Transform(geom.Legs[i].HipInCom * scale, qBody);
float dx = (comPos.X + hipOff.X) - ankle.X;
float dz = (comPos.Z + hipOff.Z) - ankle.Z;
float horizSq = dx * dx + dz * dz;
float maxReach = geom.Legs[i].MaxLegReach * scale * 0.99f;
float remSq = MathF.Max(0f, maxReach * maxReach - horizSq);
float maxComY = ankle.Y - hipOff.Y + MathF.Sqrt(remSq);
if (maxComY < maxLegComY)
{
maxLegComY = maxComY;
}
}
if (!float.IsPositiveInfinity(maxLegComY))
{
targetY = MathF.Min(targetY, MathF.Max(comGroundY + geom.ModelHalfHeight * scale * 0.72f, maxLegComY));
}
}
float fyDes = MathF.Max(0f,
mass * Gravity +
@ -892,7 +1006,8 @@ namespace RustToDust.Ymir
mass * 10.5f * (terrainRateY - vel.Y));
float penThresh = MathF.Min(geom.ModelHalfHeight * scale, rideHeight) - 0.01f * scale;
float hullBottomPen = (comGroundY + penThresh) - comPos.Y;
if (!ws.IsAirborne && terrainNormal.Y < 0.975f && (vel.Y - terrainRateY) < 0.4f && comPos.Y <= targetY + 0.45f * scale)
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)
{
fyDes = MathF.Max(fyDes, mass * Gravity);
}
@ -952,7 +1067,6 @@ namespace RustToDust.Ymir
}
float thrust = grid.ComputeDriveThrust();
float maxSpd = MathF.Max(4f, grid.Spec.MaxSpeed);
float driveGain = MathF.Max(mass * 5.2f, (thrust / maxSpd) * 2.0f) * avgIntegrity;
float latGain = mass * 8.5f * avgIntegrity;
if (idleCmd)
@ -1008,9 +1122,22 @@ namespace RustToDust.Ymir
float fxDes = horizDriveForce.X;
float fzDes = horizDriveForce.Z;
// Inertial attitude PD torque + subtle accel pitch lean + turn bank + crippled-leg limp sag + yaw PD torque
Vector3 desiredUp = Vector3.Normalize(Vector3.Lerp(Vector3.UnitY, terrainNormal, 0.22f));
float accelPitch = Math.Clamp((fwdDes - fwdVel) * 0.008f + fwdDes * 0.003f, -0.04f, 0.06f);
// Inertial attitude PD torque + Dorsal quadruped terrain-slope alignment + subtle accel pitch lean + turn bank + crippled-leg limp sag + yaw PD torque
Vector3 desiredUp;
if (n == 4)
{
float slopePitch = MathF.Asin(Math.Clamp(Vector3.Dot(fwd, hullSlopeNormal), -0.45f, 0.45f)) * 0.85f;
float slopeRoll = MathF.Asin(Math.Clamp(Vector3.Dot(right, hullSlopeNormal), -0.40f, 0.40f)) * 0.85f;
desiredUp = Vector3.Normalize(Vector3.UnitY + fwd * MathF.Sin(slopePitch) + right * MathF.Sin(slopeRoll));
}
else
{
desiredUp = Vector3.Normalize(Vector3.Lerp(Vector3.UnitY, terrainNormal, 0.22f));
}
// Do not lean quadruped nose down into an uphill slope when accelerating
float accelPitch = (n == 4 && hullSlopeNormal.Y < 0.985f)
? 0f
: Math.Clamp((fwdDes - fwdVel) * 0.008f + fwdDes * 0.003f, -0.04f, 0.06f);
float limpLatLean = 0f;
float limpFwdLean = 0f;
if (n == 2)
@ -1028,10 +1155,15 @@ namespace RustToDust.Ymir
limpFwdLean = (rearInt - frontInt) * 0.065f;
}
Vector3 driveBank = new Vector3(fxDes, 0f, fzDes) / MathF.Max(1f, mass * Gravity) * 0.08f;
if (n == 4 && hullSlopeNormal.Y < 0.985f)
{
// Preserve lateral turn bank only on sloped quadrupeds so uphill drive never pitches nose into hillside
driveBank = right * Vector3.Dot(driveBank, right);
}
desiredUp = Vector3.Normalize(desiredUp + fwd * (accelPitch + limpFwdLean) - right * limpLatLean + driveBank);
// Cap desiredUp tilt to <= 8.6 deg so free-fall off Mesa cliffs stays well within 22 deg upright margin
const float maxDesiredTiltRad = 0.150f;
// 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;
float dotUp = Math.Clamp(desiredUp.Y, -1f, 1f);
if (MathF.Acos(dotUp) > maxDesiredTiltRad)
{

View file

@ -839,5 +839,199 @@ namespace RustToDust.Tests
grid.GetLegIntegrities(legs);
Assert.True(legs[1] < 1.0f, $"Expected right leg integrity < 1.0 after (3,4) destroyed, got {legs[1]:F3}");
}
[Fact]
public void DorsalWalkers_AimedShotsWithSpreadAt80m_DoNotSailOverTop()
{
foreach (var spec in new[] { Catalog.Bastion, Catalog.Manticore })
{
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert);
for (int i = 2; i < session.State.Contenders.Count; i++)
{
session.SetContenderPose(i, 900f + i * 16f, 900f);
}
// Target contender 1 on flat ground facing perpendicular so silhouette is clean
session.SetContenderPose(1, 0f, 80f, MathF.PI * 0.5f);
session.State.Contenders[1].Grid.SwapChassis(spec);
session.SetContenderPose(1, 0f, 80f, MathF.PI * 0.5f);
// Shooter contender 0 at 80m away
session.SetContenderPose(0, 0f, 0f, 0f);
for (int t = 0; t < 45; t++)
{
session.Step(new PlayerInput(0f, 0f, 0f, 80f, false, false, false));
}
var target = session.State.Contenders[1];
var shooter = session.State.Contenders[0];
ulong targetStableId = ArenaSession.ContenderStableIdBase + (ulong)target.Id;
float aimY = MatchRules.GetTargetAimY(target.Y, target.Grid.Spec.HalfHeight);
Vector3 muzzle = new(shooter.X, shooter.Y + shooter.Grid.Spec.HalfHeight * 0.25f, shooter.Z + shooter.Grid.Spec.HalfLength + 0.35f);
Vector3 baseDir = Vector3.Normalize(new Vector3(target.X - muzzle.X, aimY - muzzle.Y, target.Z - muzzle.Z));
var rng = new Random(12345);
const int shotCount = 250;
const float totalSpread = 0.015f;
int overTopMisses = 0;
int hits = 0;
for (int s = 0; s < shotCount; s++)
{
float yawJitter = ((float)rng.NextDouble() * 2f - 1f) * totalSpread;
float pitchJitter = ((float)rng.NextDouble() * 2f - 1f) * (totalSpread * 0.35f);
var yawQ = Quaternion.CreateFromAxisAngle(Vector3.UnitY, yawJitter);
var rotated = Vector3.Transform(baseDir, yawQ);
var right = Vector3.Cross(rotated, Vector3.UnitY);
if (right.LengthSquared() > 1e-4f)
{
rotated = Vector3.Transform(rotated, Quaternion.CreateFromAxisAngle(Vector3.Normalize(right), pitchJitter));
}
var dir = Vector3.Normalize(rotated);
var hit = session.World.CastRayClosest((muzzle.X, muzzle.Y, muzzle.Z), (dir.X * 160f, dir.Y * 160f, dir.Z * 160f));
if (hit.Hit && hit.StableId == targetStableId)
{
hits++;
}
else
{
float tPlane = (target.Z - muzzle.Z) / MathF.Max(1e-4f, dir.Z);
float yAtTarget = muzzle.Y + dir.Y * tPlane;
if (yAtTarget > target.Y)
{
overTopMisses++;
}
}
}
float overTopRate = (float)overTopMisses / shotCount;
_output.WriteLine($"{spec.Id}: 80m hits={hits}/{shotCount}, overTopMisses={overTopMisses} ({overTopRate * 100f:F2}%)");
Assert.True(overTopRate < 0.02f, $"{spec.Id}: over-top miss rate {overTopRate * 100f:F2}% >= 2%");
}
}
[Fact]
public void HybridB_BastionAndManticore_ExactSionSteepHills_ClimbWithoutBeaching()
{
var failingSites = new (string Name, float X, float Z)[]
{
("Site#9", 459.6f, -385.7f),
("Site#12", 413.0f, 589.8f),
("Site#7", 0.0f, -580.0f),
("Site#2", 360.4f, -252.4f),
};
foreach (var spec in new[] { Catalog.Bastion, Catalog.Manticore })
{
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion);
for (int i = 1; i < session.State.Contenders.Count; i++)
{
session.SetContenderPose(i, 900f + i * 16f, 900f);
}
session.SetContenderPose(0, failingSites[0].X, failingSites[0].Z, 0f);
session.State.SpawnChassisDrop(failingSites[0].X, failingSites[0].Z, spec);
Assert.True(session.TrySwapNearbyChassis(), $"Failed swap to {spec.Id}");
var player = session.State.Player;
foreach (var site in failingSites)
{
var (nx, ny, nz) = session.State.Terrain.SampleNormal(site.X, site.Z);
float uphillYaw = MathF.Atan2(-nx, -nz);
session.SetContenderPose(0, site.X, site.Z, uphillYaw);
Vector2 startPos = new(player.X, player.Z);
Vector2 fwdDir = new(MathF.Sin(uphillYaw), MathF.Cos(uphillYaw));
float gStart = session.State.Terrain.SampleHeight(player.X, player.Z);
for (int t = 0; t < 120; t++)
{
session.Step(new PlayerInput(
Throttle: 1f,
Steer: 0f,
AimWorldX: player.X + fwdDir.X * 50f,
AimWorldZ: player.Z + fwdDir.Y * 50f,
Fire: false,
InteractPickup: false,
Brake: false));
}
float disp2s = Vector2.Dot(new Vector2(player.X, player.Z) - startPos, fwdDir);
float endSpd = player.Speed;
float gEnd = session.State.Terrain.SampleHeight(player.X, player.Z);
_output.WriteLine(
$"{spec.Id} {site.Name} ({site.X:F1},{site.Z:F1}) ny={ny:F3}: disp2s={disp2s:F2}m endSpd={endSpd:F2}m/s climb={(gEnd - gStart):F2}m");
Assert.True(disp2s >= 8.0f, $"{spec.Id} beached at {site.Name} ({site.X:F1},{site.Z:F1}) ny={ny:F3}: disp2s={disp2s:F2}m < 8.0m");
Assert.True(endSpd >= 4.0f, $"{spec.Id} stalled at {site.Name} ({site.X:F1},{site.Z:F1}) ny={ny:F3}: endSpd={endSpd:F2}m/s < 4.0m/s");
}
}
}
[Fact]
public void HybridB_Bastion_StationaryFacingHill_DoesNotHyperExtendLegs()
{
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion);
for (int i = 1; i < session.State.Contenders.Count; i++)
{
session.SetContenderPose(i, 900f + i * 16f, 900f);
}
const float siteX = 0f;
const float siteZ = -180f;
var (nx, _, nz) = session.State.Terrain.SampleNormal(siteX, siteZ);
float uphillYaw = (nx * nx + nz * nz) > 1e-5f ? MathF.Atan2(-nx, -nz) : 0f;
session.SetContenderPose(0, siteX, siteZ, uphillYaw);
session.State.SpawnChassisDrop(siteX, siteZ, Catalog.Bastion);
Assert.True(session.TrySwapNearbyChassis(), "Failed swap to Bastion at Site#0");
session.SetContenderPose(0, siteX, siteZ, uphillYaw);
var player = session.State.Player;
var ws = session.GetWalkerState(true, player.Id)!;
float modelRide = WalkerLocomotion.GetRideHeight(Catalog.Bastion);
float maxRelCom = 0f;
float maxReachOverflow = 0f;
for (int t = 0; t < 120; t++)
{
session.Step(new PlayerInput(
Throttle: 0f,
Steer: 0f,
AimWorldX: player.X + MathF.Sin(uphillYaw) * 50f,
AimWorldZ: player.Z + MathF.Cos(uphillYaw) * 50f,
Fire: false,
InteractPickup: false,
Brake: false));
float groundY = session.State.Terrain.SampleHeight(player.X, player.Z);
float relCom = player.Y - groundY;
if (relCom > maxRelCom)
{
maxRelCom = relCom;
}
Vector3 comPos = new(player.X, player.Y, player.Z);
Quaternion qBody = new(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
for (int leg = 0; leg < ws.Geom.LegCount; leg++)
{
Vector3 hipW = comPos + Vector3.Transform(ws.Geom.Legs[leg].HipInCom * ws.GeomScale, qBody);
Vector3 ankleW = ws.FootSole[leg] + ws.FootNormal[leg] * (ws.Geom.Legs[leg].AnkleH * ws.GeomScale);
float dist = Vector3.Distance(hipW, ankleW);
float maxReach = ws.Geom.Legs[leg].MaxLegReach * ws.GeomScale;
float overflow = dist - maxReach;
if (overflow > maxReachOverflow)
{
maxReachOverflow = overflow;
}
}
}
_output.WriteLine($"Bastion idle Site#0: maxRelCom={maxRelCom:F3}m (ride={modelRide:F3}m) maxReachOverflow={maxReachOverflow:F4}m");
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");
}
}
}