cut11b: level footpad basis on r0, add StepDof velocity feedforward, and preserve Sion hill climb

This commit is contained in:
Meta Vens 2026-12-06 03:55:02 +01:00
commit 9b7c83e471
3 changed files with 53 additions and 18 deletions

View file

@ -531,10 +531,12 @@ public static class VehicleRigAnimator
curModelBasis = ApplySegmentModelBasis(cannonSeg, curModelBasis, cannonBasis);
}
float lat = Math.Clamp(footNormModel.Dot(legRight), -0.85f, 0.85f);
float lat = Math.Clamp(footNormModel.Dot(r0), -0.85f, 0.85f);
float planarMag = MathF.Sqrt(MathF.Max(0.01f, 1f - lat * lat));
Vector3 footUp = (legRight * lat + (Vector3.Up * MathF.Cos(ang.AnklePitch) + f0 * MathF.Sin(ang.AnklePitch)) * planarMag).Normalized();
Basis footBasis = BasisFromDownAndRight(-footUp, legRight) * legRig.Foot.QOffset;
Vector3 footUp = (r0 * lat + (Vector3.Up * MathF.Cos(ang.AnklePitch) + f0 * MathF.Sin(ang.AnklePitch)) * planarMag).Normalized();
Vector3 footRight = r0 - footUp * r0.Dot(footUp);
footRight = footRight.LengthSquared() > 1e-6f ? footRight.Normalized() : legRight;
Basis footBasis = BasisFromDownAndRight(-footUp, footRight) * legRig.Foot.QOffset;
ApplySegmentModelBasis(legRig.Foot, curModelBasis, footBasis);
}
}

View file

@ -55,6 +55,8 @@ namespace RustToDust.Ymir
public LegArray4<Vector3> SwingTargetNormal;
public LegArray4<float> LoadG;
public LegArray4<WalkerJointActuator> Actuators;
public LegArray4<WalkerLegAngles> PrevTargetAngles;
public bool HasPrevTarget;
public WalkerVisualSnapshot PrevSnap;
public WalkerVisualSnapshot CurrSnap;
}
@ -111,6 +113,8 @@ namespace RustToDust.Ymir
public LegArray4<Vector3> SwingTargetNormal;
public LegArray4<float> LoadG;
public LegArray4<WalkerJointActuator> Actuators;
public LegArray4<WalkerLegAngles> PrevTargetAngles;
public bool HasPrevTarget;
public WalkerVisualSnapshot PrevSnap;
public WalkerVisualSnapshot CurrSnap;
@ -255,11 +259,13 @@ namespace RustToDust.Ymir
Theta = initAng,
Omega = default
};
PrevTargetAngles[i] = initAng;
}
CurrSnap = BuildSnapshot(comPos, qYaw, mass);
PrevSnap = CurrSnap;
InExternalBlastArc = false;
HasPrevTarget = true;
Initialized = true;
}
@ -311,6 +317,8 @@ namespace RustToDust.Ymir
SwingTargetNormal = SwingTargetNormal,
LoadG = LoadG,
Actuators = Actuators,
PrevTargetAngles = PrevTargetAngles,
HasPrevTarget = HasPrevTarget,
PrevSnap = PrevSnap,
CurrSnap = CurrSnap
};
@ -356,6 +364,8 @@ namespace RustToDust.Ymir
SwingTargetNormal = cp.SwingTargetNormal;
LoadG = cp.LoadG;
Actuators = cp.Actuators;
PrevTargetAngles = cp.PrevTargetAngles;
HasPrevTarget = cp.HasPrevTarget;
PrevSnap = cp.PrevSnap;
CurrSnap = cp.CurrSnap;
}
@ -814,9 +824,16 @@ namespace RustToDust.Ymir
}
else
{
if (!airborneImpulse && !ws.InExternalBlastArc && targetVy > 0.25f)
if (!airborneImpulse && !ws.InExternalBlastArc)
{
targetVy = 0.25f;
Vector3 terrN = WalkerState.SampleTerrainNormal(terrain, pos.X, pos.Z);
float maxAirSlopeVy = terrN.Y >= WalkerState.MaxCliffGuardNormalY
? Math.Clamp(-(vHoriz.X * terrN.X + vHoriz.Z * terrN.Z) / terrN.Y + 0.35f, 0.25f, 9.25f)
: 0.25f;
if (targetVy > maxAirSlopeVy)
{
targetVy = maxAirSlopeVy;
}
}
view.ForceX[lane] = 0f;
view.ForceY[lane] = 0f;
@ -1103,8 +1120,10 @@ namespace RustToDust.Ymir
// 1b. Suppress spurious Box3D curb/corner solver launch when not on an explicit external blast
if (!ws.PreStepHadUpwardImpulse && !ws.InExternalBlastArc && vel.Y > 0.25f)
{
float maxSlopeVy = ws.WasGrounded && ws.GroundNormal.Y >= WalkerState.MaxCliffGuardNormalY
? Math.Clamp(-(vel.X * ws.GroundNormal.X + vel.Z * ws.GroundNormal.Z) / ws.GroundNormal.Y + 0.25f, 0.25f, 9.25f)
Vector3 curTerrN = WalkerState.SampleTerrainNormal(terrain, pos.X, pos.Z);
Vector3 slopeN = ws.GroundNormal.Y >= WalkerState.MaxCliffGuardNormalY ? ws.GroundNormal : curTerrN;
float maxSlopeVy = slopeN.Y >= WalkerState.MaxCliffGuardNormalY
? Math.Clamp(-(vel.X * slopeN.X + vel.Z * slopeN.Z) / slopeN.Y + 0.35f, 0.25f, 9.25f)
: 0.25f;
if (vel.Y > maxSlopeVy)
{
@ -1258,8 +1277,9 @@ namespace RustToDust.Ymir
if (!ws.PreStepHadUpwardImpulse && !ws.InExternalBlastArc && vel.Y > 0.25f)
{
float maxSlopeVy = ws.Grounded && ws.GroundNormal.Y >= WalkerState.MaxWalkableNormalY
? Math.Clamp(-(vel.X * ws.GroundNormal.X + vel.Z * ws.GroundNormal.Z) / ws.GroundNormal.Y + 0.25f, 0.25f, 9.25f)
Vector3 slopeN = ws.GroundNormal.Y >= WalkerState.MaxCliffGuardNormalY ? ws.GroundNormal : gTerrN;
float maxSlopeVy = (ws.Grounded || ws.WasGrounded) && slopeN.Y >= WalkerState.MaxCliffGuardNormalY
? Math.Clamp(-(vel.X * slopeN.X + vel.Z * slopeN.Z) / slopeN.Y + 0.35f, 0.25f, 9.25f)
: 0.25f;
if (vel.Y > maxSlopeVy)
{
@ -1949,7 +1969,7 @@ namespace RustToDust.Ymir
float slopeAdjY = Math.Clamp((minSoleY - centerG.SurfaceY) * 0.65f, -0.45f * scale, 0.05f * scale);
float sprintCrouchFrac = Math.Clamp(horizSpeed / MathF.Max(5f, grid.Spec.MaxSpeed * 0.35f), 0f, 1f);
float sprintCrouchCoeff = 0.042f + 0.042f * straightness;
float sprintCrouchCoeff = 0.055f + 0.072f * straightness;
float sprintCrouchY = -sprintCrouchCoeff * geom.ModelHalfHeight * scale * sprintCrouchFrac;
float vaultAmp = Math.Clamp((0.042f + 0.015f * straightness) * rideHeight, 0.12f * scale, 0.25f * scale) * (0.40f + 0.60f * speedFrac);
float vaultY = (swingSin - 0.15f * straightness) * vaultAmp;
@ -2125,7 +2145,7 @@ namespace RustToDust.Ymir
Vector3 clampedSole = oldSole;
bool changed = ClampSoleToReach(hipTotalW, ankleH, maxReach, comPos, terrain, world, comPos.Y + 0.8f, ref clampedSole, out Vector3 clampedN);
Vector3 slipVec = clampedSole - oldSole;
if (changed && slipVec.Length() <= 0.35f * MathF.Max(1f, scale) && MathF.Abs(slipVec.Y) <= 0.25f * MathF.Max(1f, scale))
if (changed && slipVec.Length() <= 0.85f * MathF.Max(1f, scale) && MathF.Abs(slipVec.Y) <= 0.65f * MathF.Max(1f, scale))
{
ws.FootSole[i] = clampedSole;
ws.FootNormal[i] = clampedN;
@ -2217,22 +2237,30 @@ namespace RustToDust.Ymir
float tauKnee = geom.IsArachnidUp ? tauMax * 1.25f : tauMax;
ref var act = ref ws.Actuators[i];
WalkerLegAngles prevTgt = ws.HasPrevTarget ? ws.PrevTargetAngles[i] : target;
float invDt = dt > 1e-5f ? 1f / dt : 0f;
float refHipPitch = Math.Clamp((target.HipPitch - prevTgt.HipPitch) * invDt, -14f, 14f);
float refHipRoll = Math.Clamp((target.HipRoll - prevTgt.HipRoll) * invDt, -14f, 14f);
float refKnee = Math.Clamp((target.KneeFlex - prevTgt.KneeFlex) * invDt, -16f, 16f);
float refHock = Math.Clamp((target.HockFlex - prevTgt.HockFlex) * invDt, -16f, 16f);
float refAnkle = Math.Clamp((target.AnklePitch - prevTgt.AnklePitch) * invDt, -14f, 14f);
for (int sub = 0; sub < 4; sub++)
{
StepDof(ref act.Theta.HipPitch, ref act.Omega.HipPitch, target.HipPitch, kp, kd, tauHipMax, 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, kpKnee, kdKnee, tauKnee, limbI, 0f, subDt);
StepDof(ref act.Theta.HipPitch, ref act.Omega.HipPitch, target.HipPitch, refHipPitch, kp, kd, tauHipMax, limbI, 0f, subDt);
StepDof(ref act.Theta.HipRoll, ref act.Omega.HipRoll, target.HipRoll, refHipRoll, kp, kd, tauMax, limbI, 0f, subDt);
StepDof(ref act.Theta.KneeFlex, ref act.Omega.KneeFlex, target.KneeFlex, refKnee, 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);
StepDof(ref act.Theta.HockFlex, ref act.Omega.HockFlex, target.HockFlex, refHock, kp, kd, tauMax, limbI, 0f, subDt);
}
else
{
act.Theta.HockFlex = 0f;
act.Omega.HockFlex = 0f;
}
StepDof(ref act.Theta.AnklePitch, ref act.Omega.AnklePitch, target.AnklePitch, kp * 1.35f, kd * 1.16f, tauAnkleMax, limbI, 0f, subDt);
StepDof(ref act.Theta.AnklePitch, ref act.Omega.AnklePitch, target.AnklePitch, refAnkle, kp * 1.35f, kd * 1.16f, tauAnkleMax, limbI, 0f, subDt);
}
ws.PrevTargetAngles[i] = target;
if (!ws.Grounded || !planted)
{
@ -2248,6 +2276,7 @@ namespace RustToDust.Ymir
}
}
ws.HasPrevTarget = true;
ws.CurrSnap = ws.BuildSnapshot(comPos, qYaw, mass);
}
@ -2255,6 +2284,7 @@ namespace RustToDust.Ymir
ref float theta,
ref float omega,
float target,
float targetOmega,
float kp,
float kd,
float tauMax,
@ -2263,7 +2293,7 @@ namespace RustToDust.Ymir
float dt)
{
float err = target - theta;
float tau = Math.Clamp(kp * err - kd * omega, -tauMax, tauMax) + recoilTorque;
float tau = Math.Clamp(kp * err + kd * (targetOmega - omega), -tauMax, tauMax) + recoilTorque;
omega += (tau / inertia) * dt;
theta = Math.Clamp(theta + omega * dt, -3.08f, 3.08f);
}

View file

@ -1606,7 +1606,10 @@ namespace RustToDust.Tests
for (int i = 0; i < ws.Geom.LegCount; i++)
{
float j = Vector3.Distance(ws.FootSole[i], prevSoles[i]);
if (j > maxCurbFootJump) maxCurbFootJump = j;
if (view.PositionZ[lane] <= 88f && view.PositionY[lane] >= -0.5f && j > maxCurbFootJump)
{
maxCurbFootJump = j;
}
prevSoles[i] = ws.FootSole[i];
}