diff --git a/src/RustToDust.Ymir/WalkerLocomotion.cs b/src/RustToDust.Ymir/WalkerLocomotion.cs index f03df20..1084fba 100644 --- a/src/RustToDust.Ymir/WalkerLocomotion.cs +++ b/src/RustToDust.Ymir/WalkerLocomotion.cs @@ -1375,6 +1375,7 @@ namespace RustToDust.Ymir float speedFrac = Math.Clamp(horizSpeed / MathF.Max(4f, grid.Spec.MaxSpeed), 0f, 1f); float straightness = Math.Clamp((geom.MeanRestExtensionRatio - 0.75f) / 0.21f, 0f, 1f); + bool jl0 = false, jl1 = false, jl2 = false, jl3 = false; if (ws.IsAirborne) { @@ -1476,22 +1477,20 @@ namespace RustToDust.Ymir ws.SwingTime += dt; ws.SwingPhase += dt / MathF.Max(minDur, effectiveDur); - // Early step-completion break if a planted leg reaches > breakFrac * MaxLegReach (with immediate emergency break past 0.975f) + // Early step-completion break if a planted leg reaches > breakFrac * 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; 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); - float reachRatio = (ankleW - hipCur).Length() / MathF.Max(0.1f, geom.Legs[i].MaxLegReach * scale); - if (reachRatio > 0.975f || (normalBreakWindow && reachRatio > breakFrac)) + if ((ankleW - hipCur).Length() > geom.Legs[i].MaxLegReach * scale * breakFrac) { earlyBreak = true; break; @@ -1606,6 +1605,11 @@ namespace RustToDust.Ymir ? Quaternion.Normalize(Quaternion.CreateFromAxisAngle(Vector3.UnitY, angVelY * MathF.Min(remainingT, effectiveDur * 0.65f)) * qYaw) : qYaw; + jl0 = p0 && !ws.Planted[0]; + jl1 = p1 && !ws.Planted[1]; + jl2 = p2 && !ws.Planted[2]; + jl3 = p3 && !ws.Planted[3]; + for (int i = 0; i < n; i++) { if (ws.Planted[i]) @@ -1613,7 +1617,7 @@ namespace RustToDust.Ymir continue; } - bool justLifted = i switch { 0 => p0, 1 => p1, 2 => p2, _ => p3 }; + bool justLifted = i switch { 0 => jl0, 1 => jl1, 2 => jl2, _ => jl3 }; float legUSwing = justLifted ? MathF.Min(uSwing, 0.45f * dt / MathF.Max(0.16f, effectiveDur * (1f - overlap))) : uSwing; @@ -1903,18 +1907,22 @@ namespace RustToDust.Ymir float ankleH = geom.Legs[i].AnkleH * scale; float maxReach = geom.Legs[i].MaxLegReach * scale * 0.995f; Vector3 oldSole = ws.FootSole[i]; - if (ws.Grounded && ws.Planted[i]) + bool justLifted = i switch { 0 => jl0, 1 => jl1, 2 => jl2, _ => jl3 }; + if (ws.Grounded && (ws.Planted[i] || justLifted)) { 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; - float drag = MathF.Sqrt((clampedSole.X - oldSole.X) * (clampedSole.X - oldSole.X) + - (clampedSole.Z - oldSole.Z) * (clampedSole.Z - oldSole.Z)); - if (drag > ws.MaxFootSlipM) + if (ws.Planted[i]) { - ws.MaxFootSlipM = drag; + 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; + } } } }