cut11b: emergency earlyBreak for fast sprinters and track arachnid knee/coxa cleanly

This commit is contained in:
Meta Vens 2026-12-06 02:24:23 +01:00
commit 5f35cd9125

View file

@ -1476,20 +1476,22 @@ 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 (with immediate emergency break past 0.975f)
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;
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 reachRatio = (ankleW - hipCur).Length() / MathF.Max(0.1f, geom.Legs[i].MaxLegReach * scale);
if (reachRatio > 0.975f || (normalBreakWindow && reachRatio > breakFrac))
{
earlyBreak = true;
break;
@ -1970,13 +1972,17 @@ namespace RustToDust.Ymir
float kd = planted ? kdStance : kdSwing;
float tauMax = tauLimitBase * legIntegrities[i];
float tauAnkleMax = tauLimitAnkle * legIntegrities[i];
// Arachnid-up KneeFlex rotates 2x HipPitch (2*alpha vs alpha) during rapid extension; track cleanly so shin does not plunge
float kpKnee = geom.IsArachnidUp ? kp * 1.85f : kp;
float kdKnee = geom.IsArachnidUp ? kd * 1.36f : kd;
float tauKnee = geom.IsArachnidUp ? tauMax * 2.4f : tauMax;
ref var act = ref ws.Actuators[i];
for (int sub = 0; sub < 4; sub++)
{
StepDof(ref act.Theta.HipPitch, ref act.Omega.HipPitch, target.HipPitch, kp, kd, tauMax, limbI, 0f, subDt);
StepDof(ref act.Theta.HipRoll, ref act.Omega.HipRoll, target.HipRoll, kp, kd, tauMax, limbI, 0f, subDt);
StepDof(ref act.Theta.KneeFlex, ref act.Omega.KneeFlex, target.KneeFlex, kp, kd, tauMax, limbI, 0f, subDt);
StepDof(ref act.Theta.KneeFlex, ref act.Omega.KneeFlex, target.KneeFlex, kpKnee, kdKnee, tauKnee, limbI, 0f, subDt);
if (geom.IsDigitigrade)
{
StepDof(ref act.Theta.HockFlex, ref act.Omega.HockFlex, target.HockFlex, kp, kd, tauMax, limbI, 0f, subDt);
@ -2209,8 +2215,10 @@ namespace RustToDust.Ymir
if (geom.IsArachnidUp)
{
float coxaYaw = MathF.Atan2(dx, MathF.Max(0.20f * scale, dz));
float planarOut = MathF.Sqrt(dx * dx + dz * dz);
float coxaYaw = planarOut > 0.20f * scale
? Math.Clamp(MathF.Atan2(dx, dz), -2.30f, 2.30f)
: MathF.Atan2(dx, 0.20f * scale);
float planarUp = dy;
float d = Math.Clamp(
MathF.Sqrt(planarOut * planarOut + planarUp * planarUp),