fix(ymir): fix sloped InitializePose ground check and continuous Phase 2->3 ClampSoleToReach

This commit is contained in:
Meta Vens 2026-12-06 02:07:09 +01:00
commit 857bbd8f30

View file

@ -155,8 +155,9 @@ namespace RustToDust.Ymir
Quaternion qYaw = WalkerLocomotion.ExtractYawQuaternion(qBody);
float rideH = Geom.ModelRideHeight * GeomScale;
var centerHit = WalkerLocomotion.SampleGroundAt(terrain, world, comPos.X, comPos.Z, comPos.Y + 0.5f, 0.25f);
float bottomClearance = (comPos.Y - rideH) - centerHit.SurfaceY;
Grounded = centerHit.Hit && centerHit.Normal.Y >= MaxCliffGuardNormalY && bottomClearance <= 0.28f;
float expectedSlopedRideH = rideH + 0.35f * GeomScale * Math.Clamp(1f / MathF.Max(0.75f, centerHit.Normal.Y) - 1f, 0f, 0.5f);
float bottomClearance = (comPos.Y - expectedSlopedRideH) - centerHit.SurfaceY;
Grounded = centerHit.Hit && centerHit.Normal.Y >= MaxCliffGuardNormalY && bottomClearance <= 0.22f;
WasGrounded = Grounded;
IsAirborne = !Grounded;
WasAirborne = IsAirborne;
@ -2122,9 +2123,12 @@ namespace RustToDust.Ymir
}
// Ground along (fx, fz) -> hipWorld is vertically out of reach (steep sidehill / cliff / airborne):
// pull progressively from (fx, fz) toward/slightly past chassisCenterWorld where uphill ground may be reachable.
// pull progressively from (fx, fz) toward chassisCenterWorld where uphill ground may be reachable,
// tracking the minimum-reach-error point so Phase 3 transitions continuously if still unreachable.
Vector2 fromSoleToCenter = new(chassisCenterWorld.X - fx, chassisCenterWorld.Z - fz);
float spanLen = fromSoleToCenter.Length();
Vector3 bestFallbackAnkle = ankle0;
float bestFallbackDist = (ankle0 - hipWorld).Length();
if (spanLen > 1e-3f)
{
for (int s = 1; s <= 10; s++)
@ -2134,17 +2138,23 @@ namespace RustToDust.Ymir
float sz = fz + fromSoleToCenter.Y * t;
var sh = SampleGroundAt(terrain, world, sx, sz, referenceMaxY);
Vector3 sAnkle = new Vector3(sx, sh.SurfaceY, sz) + sh.Normal * ankleH;
if ((sAnkle - hipWorld).Length() <= maxReach)
float sDist = (sAnkle - hipWorld).Length();
if (sDist <= maxReach)
{
sole = new Vector3(sx, sh.SurfaceY, sz);
normal = sh.Normal;
return true;
}
if (sDist < bestFallbackDist)
{
bestFallbackDist = sDist;
bestFallbackAnkle = sAnkle;
}
}
}
// Still unreachable (cliff overhang, freefall, or steep sidehill beyond reach): clamp on 3D reach sphere.
Vector3 delta = ankle0 - hipWorld;
Vector3 delta = (bestFallbackDist < (ankle0 - hipWorld).Length() - 0.15f ? bestFallbackAnkle : ankle0) - hipWorld;
float dist = delta.Length();
Vector3 clampedAnkle = dist > 1e-5f
? hipWorld + delta * (maxReach / dist)