From 857bbd8f300054cf52f87a9d42b65f6b870d6de3 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 6 Dec 2026 02:07:09 +0100 Subject: [PATCH] fix(ymir): fix sloped InitializePose ground check and continuous Phase 2->3 ClampSoleToReach --- src/RustToDust.Ymir/WalkerLocomotion.cs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/RustToDust.Ymir/WalkerLocomotion.cs b/src/RustToDust.Ymir/WalkerLocomotion.cs index 7c0fcef..4a74d9d 100644 --- a/src/RustToDust.Ymir/WalkerLocomotion.cs +++ b/src/RustToDust.Ymir/WalkerLocomotion.cs @@ -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)