cut11b: add trailing velocity headroom and defer early break over air
This commit is contained in:
parent
3431a93ca5
commit
7fc5d716e0
1 changed files with 41 additions and 11 deletions
|
|
@ -1477,16 +1477,14 @@ namespace RustToDust.Ymir
|
|||
ws.SwingTime += dt;
|
||||
ws.SwingPhase += dt / MathF.Max(minDur, effectiveDur);
|
||||
|
||||
// Early step-completion break if a planted leg reaches > breakFrac * MaxLegReach,
|
||||
// or kinematic 1-tick lookahead on trailing legs that would exceed 0.990f next tick
|
||||
// Early step-completion break if a planted leg reaches > effectiveBreakFrac * MaxLegReach
|
||||
bool earlyBreak = false;
|
||||
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);
|
||||
Quaternion curQTotal = Quaternion.Normalize(qYaw * Quaternion.CreateFromYawPitchRoll(0f, ws.LeanPitch, ws.LeanRoll));
|
||||
float breakFrac = n == 4 ? 0.945f : 0.955f;
|
||||
bool normalBreakWindow = ws.SwingTime >= minBreakTime && ws.SwingPhase > overlap + 0.15f;
|
||||
float baseBreakFrac = n == 4 ? 0.945f : 0.955f;
|
||||
Vector3 horizStep = new(vel.X * dt, 0f, vel.Z * dt);
|
||||
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 ankleW = ws.FootSole[i] + ws.FootNormal[i] * (geom.Legs[i].AnkleH * 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;
|
||||
float nextRatio = isTrailing ? (ankleW - (hipCur + horizStep)).Length() / legMaxReach : 0f;
|
||||
if ((isTrailing && nextRatio > 0.990f) || (normalBreakWindow && reachRatio > breakFrac))
|
||||
float trailHeadroom = isTrailing
|
||||
? Math.Clamp(horizSpeed * dt * 0.55f / legMaxReach, 0f, 0.085f)
|
||||
: 0f;
|
||||
if ((ankleW - hipCur).Length() > legMaxReach * (baseBreakFrac - trailHeadroom))
|
||||
{
|
||||
earlyBreak = true;
|
||||
break;
|
||||
|
|
@ -1511,6 +1510,9 @@ namespace RustToDust.Ymir
|
|||
if (u >= 1.0f)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
if (!IsInGroup(n, i, ws.StanceGroup))
|
||||
|
|
@ -1550,12 +1552,40 @@ namespace RustToDust.Ymir
|
|||
landedNorm = fallbackNorm;
|
||||
}
|
||||
}
|
||||
ws.FootSole[i] = landedSole;
|
||||
ws.FootNormal[i] = landedNorm;
|
||||
ws.Planted[i] = true;
|
||||
if (earlyBreak && ws.SwingPhase < 1.0f)
|
||||
{
|
||||
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
|
||||
float massScale = MathF.Sqrt(MathF.Max(800f, mass) / 2600f);
|
||||
ws.CompressionVelY -= 2.30f * massScale * (0.45f + 0.55f * speedFrac);
|
||||
|
|
|
|||
Loading…
Reference in a new issue