diff --git a/src/RustToDust.Ymir/WalkerLocomotion.cs b/src/RustToDust.Ymir/WalkerLocomotion.cs index 1084fba..7a392ab 100644 --- a/src/RustToDust.Ymir/WalkerLocomotion.cs +++ b/src/RustToDust.Ymir/WalkerLocomotion.cs @@ -1477,20 +1477,27 @@ namespace RustToDust.Ymir ws.SwingTime += dt; 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 > breakFrac * MaxLegReach, + // or kinematic 1-tick lookahead on trailing legs that would exceed 0.990f next tick bool earlyBreak = false; float minBreakTime = Math.Clamp(minDur * (ws.FirstStepFromIdle ? 0.68f : 0.90f), 0.075f, 0.22f); - if (ws.SwingTime >= minBreakTime && ws.SwingPhase > overlap + 0.15f) + if (ws.SwingPhase > overlap + 0.05f) { 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; + Vector3 horizStep = new(vel.X * dt, 0f, vel.Z * dt); for (int i = 0; i < n; i++) { if (!ws.Planted[i]) continue; 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); - if ((ankleW - hipCur).Length() > geom.Legs[i].MaxLegReach * scale * breakFrac) + 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)) { earlyBreak = true; break; @@ -1907,22 +1914,18 @@ namespace RustToDust.Ymir float ankleH = geom.Legs[i].AnkleH * scale; float maxReach = geom.Legs[i].MaxLegReach * scale * 0.995f; Vector3 oldSole = ws.FootSole[i]; - bool justLifted = i switch { 0 => jl0, 1 => jl1, 2 => jl2, _ => jl3 }; - if (ws.Grounded && (ws.Planted[i] || justLifted)) + if (ws.Grounded && ws.Planted[i]) { Vector3 clampedSole = oldSole; if (ClampSoleToReach(hipTotalW, ankleH, maxReach, comPos, terrain, world, comPos.Y + 0.8f, ref clampedSole, out Vector3 clampedN)) { ws.FootSole[i] = clampedSole; ws.FootNormal[i] = clampedN; - if (ws.Planted[i]) + float drag = MathF.Sqrt((clampedSole.X - oldSole.X) * (clampedSole.X - oldSole.X) + + (clampedSole.Z - oldSole.Z) * (clampedSole.Z - oldSole.Z)); + if (drag > ws.MaxFootSlipM) { - float drag = MathF.Sqrt((clampedSole.X - oldSole.X) * (clampedSole.X - oldSole.X) + - (clampedSole.Z - oldSole.Z) * (clampedSole.Z - oldSole.Z)); - if (drag > ws.MaxFootSlipM) - { - ws.MaxFootSlipM = drag; - } + ws.MaxFootSlipM = drag; } } }