diff --git a/src/RustToDust.Ymir/WalkerLocomotion.cs b/src/RustToDust.Ymir/WalkerLocomotion.cs index 46add9f..f29671b 100644 --- a/src/RustToDust.Ymir/WalkerLocomotion.cs +++ b/src/RustToDust.Ymir/WalkerLocomotion.cs @@ -1717,6 +1717,8 @@ namespace RustToDust.Ymir ws.SwingPhase = earlyBreak ? overlap : 0f; u = ws.SwingPhase; + Vector3 curPelvisEst = Vector3.Transform(ws.PelvisOffset, qYaw); + Quaternion curQEst = Quaternion.Normalize(qYaw * Quaternion.CreateFromYawPitchRoll(0f, ws.LeanPitch, ws.LeanRoll)); for (int i = 0; i < n; i++) { bool keepOldPlanted = ws.Planted[i] && !earlyBreak; @@ -1727,13 +1729,27 @@ namespace RustToDust.Ymir ws.SwingTargetSole[i] = ws.FootSole[i]; ws.SwingTargetNormal[i] = ws.FootNormal[i]; } - ws.Planted[i] = IsInGroup(n, i, ws.StanceGroup) - ? (ws.Planted[i] || ws.FootSole[i].Y <= SampleGroundAt(terrain, world, ws.FootSole[i].X, ws.FootSole[i].Z, comPos.Y + 0.8f).SurfaceY + 0.055f * scale) - : keepOldPlanted; + if (IsInGroup(n, i, ws.StanceGroup)) + { + if (!ws.Planted[i]) + { + var gCheck = SampleGroundAt(terrain, world, ws.FootSole[i].X, ws.FootSole[i].Z, comPos.Y + 0.8f); + Vector3 hipEst = comPos + curPelvisEst + Vector3.Transform(geom.Legs[i].HipInCom * scale, curQEst); + Vector3 ankEst = ws.FootSole[i] + gCheck.Normal * (geom.Legs[i].AnkleH * scale); + ws.Planted[i] = ws.FootSole[i].Y <= gCheck.SurfaceY + 0.055f * scale && + (ankEst - hipEst).Length() <= geom.Legs[i].MaxLegReach * scale * 0.995f; + } + } + else + { + ws.Planted[i] = keepOldPlanted; + } } } else { + Vector3 curPelvisEst = Vector3.Transform(ws.PelvisOffset, qYaw); + Quaternion curQEst = Quaternion.Normalize(qYaw * Quaternion.CreateFromYawPitchRoll(0f, ws.LeanPitch, ws.LeanRoll)); for (int i = 0; i < n; i++) { if (IsInGroup(n, i, ws.StanceGroup)) @@ -1741,7 +1757,10 @@ namespace RustToDust.Ymir if (!ws.Planted[i]) { var gCheck = SampleGroundAt(terrain, world, ws.FootSole[i].X, ws.FootSole[i].Z, comPos.Y + 0.8f); - ws.Planted[i] = ws.FootSole[i].Y <= gCheck.SurfaceY + 0.055f * scale; + Vector3 hipEst = comPos + curPelvisEst + Vector3.Transform(geom.Legs[i].HipInCom * scale, curQEst); + Vector3 ankEst = ws.FootSole[i] + gCheck.Normal * (geom.Legs[i].AnkleH * scale); + ws.Planted[i] = ws.FootSole[i].Y <= gCheck.SurfaceY + 0.055f * scale && + (ankEst - hipEst).Length() <= geom.Legs[i].MaxLegReach * scale * 0.995f; } } else @@ -2207,6 +2226,15 @@ namespace RustToDust.Ymir ProjectSoleAboveGroundWithinReach(hipTotalW, ankleH, maxReach, terrain, world, comPos.Y + 0.8f, 0f, ref nextSole, out Vector3 pNorm); ws.FootNormal[i] = pNorm; } + Vector3 nextDelta = (nextSole + ws.FootNormal[i] * ankleH) - hipTotalW; + float nextDist = nextDelta.Length(); + float unplantMaxR = maxReach * 1.055f; + if (nextDist > unplantMaxR && nextDist > 1e-5f) + { + Vector3 uAnk = hipTotalW + nextDelta * (unplantMaxR / nextDist); + nextSole = uAnk - ws.FootNormal[i] * ankleH; + ProjectSoleAboveGroundWithinReach(hipTotalW, ankleH, unplantMaxR, terrain, world, comPos.Y + 0.8f, 0f, ref nextSole, out _); + } ws.FootSole[i] = nextSole; } }