cut11b(ymir): require reachable ankle to plant and bound unplant step within 3D reach

This commit is contained in:
Meta Vens 2026-12-06 04:41:19 +01:00
commit a7c0bc03f9

View file

@ -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;
}
}