cut11b: add trailing velocity headroom and defer early break over air

This commit is contained in:
Meta Vens 2026-12-06 02:31:29 +01:00
commit 7fc5d716e0

View file

@ -1477,16 +1477,14 @@ namespace RustToDust.Ymir
ws.SwingTime += dt; ws.SwingTime += dt;
ws.SwingPhase += dt / MathF.Max(minDur, effectiveDur); ws.SwingPhase += dt / MathF.Max(minDur, effectiveDur);
// Early step-completion break if a planted leg reaches > breakFrac * MaxLegReach, // Early step-completion break if a planted leg reaches > effectiveBreakFrac * MaxLegReach
// or kinematic 1-tick lookahead on trailing legs that would exceed 0.990f next tick
bool earlyBreak = false; bool earlyBreak = false;
float minBreakTime = Math.Clamp(minDur * (ws.FirstStepFromIdle ? 0.68f : 0.90f), 0.075f, 0.22f); float minBreakTime = Math.Clamp(minDur * (ws.FirstStepFromIdle ? 0.68f : 0.90f), 0.075f, 0.22f);
if (ws.SwingPhase > overlap + 0.05f) if (ws.SwingTime >= minBreakTime && ws.SwingPhase > overlap + 0.15f)
{ {
Vector3 curPelvisShift = Vector3.Transform(ws.PelvisOffset, qYaw); Vector3 curPelvisShift = Vector3.Transform(ws.PelvisOffset, qYaw);
Quaternion curQTotal = Quaternion.Normalize(qYaw * Quaternion.CreateFromYawPitchRoll(0f, ws.LeanPitch, ws.LeanRoll)); Quaternion curQTotal = Quaternion.Normalize(qYaw * Quaternion.CreateFromYawPitchRoll(0f, ws.LeanPitch, ws.LeanRoll));
float breakFrac = n == 4 ? 0.945f : 0.955f; float baseBreakFrac = n == 4 ? 0.945f : 0.955f;
bool normalBreakWindow = ws.SwingTime >= minBreakTime && ws.SwingPhase > overlap + 0.15f;
Vector3 horizStep = new(vel.X * dt, 0f, vel.Z * dt); Vector3 horizStep = new(vel.X * dt, 0f, vel.Z * dt);
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
{ {
@ -1494,10 +1492,11 @@ namespace RustToDust.Ymir
Vector3 hipCur = comPos + curPelvisShift + Vector3.Transform(geom.Legs[i].HipInCom * scale, curQTotal); Vector3 hipCur = comPos + curPelvisShift + Vector3.Transform(geom.Legs[i].HipInCom * scale, curQTotal);
Vector3 ankleW = ws.FootSole[i] + ws.FootNormal[i] * (geom.Legs[i].AnkleH * scale); Vector3 ankleW = ws.FootSole[i] + ws.FootNormal[i] * (geom.Legs[i].AnkleH * scale);
float legMaxReach = MathF.Max(0.1f, geom.Legs[i].MaxLegReach * scale); float legMaxReach = MathF.Max(0.1f, geom.Legs[i].MaxLegReach * scale);
float reachRatio = (ankleW - hipCur).Length() / legMaxReach;
bool isTrailing = (ankleW.X - hipCur.X) * horizStep.X + (ankleW.Z - hipCur.Z) * horizStep.Z < 0f; bool isTrailing = (ankleW.X - hipCur.X) * horizStep.X + (ankleW.Z - hipCur.Z) * horizStep.Z < 0f;
float nextRatio = isTrailing ? (ankleW - (hipCur + horizStep)).Length() / legMaxReach : 0f; float trailHeadroom = isTrailing
if ((isTrailing && nextRatio > 0.990f) || (normalBreakWindow && reachRatio > breakFrac)) ? Math.Clamp(horizSpeed * dt * 0.55f / legMaxReach, 0f, 0.085f)
: 0f;
if ((ankleW - hipCur).Length() > legMaxReach * (baseBreakFrac - trailHeadroom))
{ {
earlyBreak = true; earlyBreak = true;
break; break;
@ -1511,6 +1510,9 @@ namespace RustToDust.Ymir
if (u >= 1.0f) if (u >= 1.0f)
{ {
Vector3 curPelvisW = Vector3.Transform(ws.PelvisOffset, qYaw); Vector3 curPelvisW = Vector3.Transform(ws.PelvisOffset, qYaw);
Span<Vector3> candSole = stackalloc Vector3[4];
Span<Vector3> candNorm = stackalloc Vector3[4];
bool deferEarlyBreak = false;
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
{ {
if (!IsInGroup(n, i, ws.StanceGroup)) if (!IsInGroup(n, i, ws.StanceGroup))
@ -1550,12 +1552,40 @@ namespace RustToDust.Ymir
landedNorm = fallbackNorm; landedNorm = fallbackNorm;
} }
} }
ws.FootSole[i] = landedSole; if (earlyBreak && ws.SwingPhase < 1.0f)
ws.FootNormal[i] = landedNorm; {
ws.Planted[i] = true; var groundCheck = SampleGroundAt(terrain, world, landedSole.X, landedSole.Z, comPos.Y + 0.8f);
if (landedSole.Y > groundCheck.SurfaceY + 0.045f * scale)
{
deferEarlyBreak = true;
}
}
candSole[i] = landedSole;
candNorm[i] = landedNorm;
} }
} }
if (deferEarlyBreak)
{
earlyBreak = false;
u = ws.SwingPhase;
}
else
{
for (int i = 0; i < n; i++)
{
if (!IsInGroup(n, i, ws.StanceGroup))
{
ws.FootSole[i] = candSole[i];
ws.FootNormal[i] = candNorm[i];
ws.Planted[i] = true;
}
}
}
}
if (u >= 1.0f)
{
// Heel-strike knee compression dip scaled by mass and gait speed // Heel-strike knee compression dip scaled by mass and gait speed
float massScale = MathF.Sqrt(MathF.Max(800f, mass) / 2600f); float massScale = MathF.Sqrt(MathF.Max(800f, mass) / 2600f);
ws.CompressionVelY -= 2.30f * massScale * (0.45f + 0.55f * speedFrac); ws.CompressionVelY -= 2.30f * massScale * (0.45f + 0.55f * speedFrac);