cut11b: guard planted contact on terrain clearance and size break time by step radius

This commit is contained in:
Meta Vens 2026-12-06 02:33:57 +01:00
commit 49a5df2fb9

View file

@ -1328,15 +1328,20 @@ namespace RustToDust.Ymir
float maxLandSnap = MathF.Max(1.05f * scale, speed3D * dt * 1.55f); float maxLandSnap = MathF.Max(1.05f * scale, speed3D * dt * 1.55f);
if (deltaLen <= maxLandSnap) if (deltaLen <= maxLandSnap)
{ {
var landCheck = SampleGroundAt(terrain, world, landedSole.X, landedSole.Z, comPos.Y + 0.6f);
bool touchesGround = landedSole.Y <= landCheck.SurfaceY + 0.055f * scale;
ws.FootSole[i] = landedSole; ws.FootSole[i] = landedSole;
ws.FootNormal[i] = landedNorm; ws.FootNormal[i] = landedNorm;
ws.SwingStartSole[i] = landedSole; ws.SwingStartSole[i] = landedSole;
ws.SwingStartNormal[i] = landedNorm; ws.SwingStartNormal[i] = landedNorm;
ws.SwingTargetSole[i] = landedSole; ws.SwingTargetSole[i] = landedSole;
ws.SwingTargetNormal[i] = landedNorm; ws.SwingTargetNormal[i] = landedNorm;
ws.Planted[i] = true; ws.Planted[i] = touchesGround;
if (touchesGround)
{
plantedOnLanding++; plantedOnLanding++;
} }
}
else else
{ {
ws.FootSole[i] += delta * (maxLandSnap / deltaLen); ws.FootSole[i] += delta * (maxLandSnap / deltaLen);
@ -1479,7 +1484,8 @@ namespace RustToDust.Ymir
// Early step-completion break if a planted leg reaches > effectiveBreakFrac * MaxLegReach // Early step-completion break if a planted leg reaches > effectiveBreakFrac * MaxLegReach
bool earlyBreak = false; bool earlyBreak = false;
float minBreakTime = Math.Clamp(minDur * (ws.FirstStepFromIdle ? 0.68f : 0.90f), 0.075f, 0.22f); float reachBreakTime = 0.72f * geom.MaxStepRadius * scale / MathF.Max(4f, horizSpeed);
float minBreakTime = Math.Clamp(MathF.Min(minDur * (ws.FirstStepFromIdle ? 0.68f : 0.90f), reachBreakTime), 0.060f, 0.22f);
if (ws.SwingTime >= minBreakTime && ws.SwingPhase > overlap + 0.15f) if (ws.SwingTime >= minBreakTime && ws.SwingPhase > overlap + 0.15f)
{ {
Vector3 curPelvisShift = Vector3.Transform(ws.PelvisOffset, qYaw); Vector3 curPelvisShift = Vector3.Transform(ws.PelvisOffset, qYaw);
@ -1512,6 +1518,8 @@ namespace RustToDust.Ymir
Vector3 curPelvisW = Vector3.Transform(ws.PelvisOffset, qYaw); Vector3 curPelvisW = Vector3.Transform(ws.PelvisOffset, qYaw);
Span<Vector3> candSole = stackalloc Vector3[4]; Span<Vector3> candSole = stackalloc Vector3[4];
Span<Vector3> candNorm = stackalloc Vector3[4]; Span<Vector3> candNorm = stackalloc Vector3[4];
Span<bool> candTouchesGround = stackalloc bool[4];
candTouchesGround.Fill(true);
bool deferEarlyBreak = false; bool deferEarlyBreak = false;
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
{ {
@ -1552,14 +1560,13 @@ namespace RustToDust.Ymir
landedNorm = fallbackNorm; landedNorm = fallbackNorm;
} }
} }
if (earlyBreak && ws.SwingPhase < 1.0f)
{
var groundCheck = SampleGroundAt(terrain, world, landedSole.X, landedSole.Z, comPos.Y + 0.8f); var groundCheck = SampleGroundAt(terrain, world, landedSole.X, landedSole.Z, comPos.Y + 0.8f);
if (landedSole.Y > groundCheck.SurfaceY + 0.045f * scale) bool touchesGround = landedSole.Y <= groundCheck.SurfaceY + 0.055f * scale;
candTouchesGround[i] = touchesGround;
if (earlyBreak && ws.SwingPhase < 1.0f && !touchesGround)
{ {
deferEarlyBreak = true; deferEarlyBreak = true;
} }
}
candSole[i] = landedSole; candSole[i] = landedSole;
candNorm[i] = landedNorm; candNorm[i] = landedNorm;
} }
@ -1578,7 +1585,7 @@ namespace RustToDust.Ymir
{ {
ws.FootSole[i] = candSole[i]; ws.FootSole[i] = candSole[i];
ws.FootNormal[i] = candNorm[i]; ws.FootNormal[i] = candNorm[i];
ws.Planted[i] = true; ws.Planted[i] = candTouchesGround[i];
} }
} }
} }
@ -1598,6 +1605,7 @@ namespace RustToDust.Ymir
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
{ {
bool keepOldPlanted = ws.Planted[i] && !earlyBreak;
if (stepping && !IsInGroup(n, i, ws.StanceGroup)) if (stepping && !IsInGroup(n, i, ws.StanceGroup))
{ {
ws.SwingStartSole[i] = ws.FootSole[i]; ws.SwingStartSole[i] = ws.FootSole[i];
@ -1605,7 +1613,9 @@ namespace RustToDust.Ymir
ws.SwingTargetSole[i] = ws.FootSole[i]; ws.SwingTargetSole[i] = ws.FootSole[i];
ws.SwingTargetNormal[i] = ws.FootNormal[i]; ws.SwingTargetNormal[i] = ws.FootNormal[i];
} }
ws.Planted[i] = !earlyBreak || IsInGroup(n, i, ws.StanceGroup); 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;
} }
} }
else else
@ -1614,7 +1624,11 @@ namespace RustToDust.Ymir
{ {
if (IsInGroup(n, i, ws.StanceGroup)) if (IsInGroup(n, i, ws.StanceGroup))
{ {
ws.Planted[i] = true; 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;
}
} }
else else
{ {