cut11b: close Soul Pass 3 blast arc decay, cliff/wall projection, and arachnid coxaYaw parity

This commit is contained in:
Meta Vens 2026-12-06 05:37:37 +01:00
commit 4a61834327
2 changed files with 752 additions and 139 deletions

View file

@ -33,6 +33,7 @@ namespace RustToDust.Ymir
public bool PendingExternalImpulse;
public bool PreStepHadUpwardImpulse;
public bool InExternalBlastArc;
public float BlastArcMaxVy;
public Vector3 PrevHorizVel;
public float MaxFootSlipM;
public Vector3 PelvisOffset;
@ -90,6 +91,7 @@ namespace RustToDust.Ymir
public bool PendingExternalImpulse;
public bool PreStepHadUpwardImpulse;
public bool InExternalBlastArc;
public float BlastArcMaxVy;
public Vector3 PrevHorizVel;
public float MaxFootSlipM;
public Vector3 PelvisOffset;
@ -265,6 +267,7 @@ namespace RustToDust.Ymir
CurrSnap = BuildSnapshot(comPos, qYaw, mass);
PrevSnap = CurrSnap;
InExternalBlastArc = false;
BlastArcMaxVy = 0f;
HasPrevTarget = true;
Initialized = true;
}
@ -295,6 +298,7 @@ namespace RustToDust.Ymir
PendingExternalImpulse = PendingExternalImpulse,
PreStepHadUpwardImpulse = PreStepHadUpwardImpulse,
InExternalBlastArc = InExternalBlastArc,
BlastArcMaxVy = BlastArcMaxVy,
PrevHorizVel = PrevHorizVel,
MaxFootSlipM = MaxFootSlipM,
PelvisOffset = PelvisOffset,
@ -342,6 +346,7 @@ namespace RustToDust.Ymir
PendingExternalImpulse = cp.PendingExternalImpulse;
PreStepHadUpwardImpulse = cp.PreStepHadUpwardImpulse;
InExternalBlastArc = cp.InExternalBlastArc;
BlastArcMaxVy = cp.BlastArcMaxVy;
PrevHorizVel = cp.PrevHorizVel;
MaxFootSlipM = cp.MaxFootSlipM;
PelvisOffset = cp.PelvisOffset;
@ -401,6 +406,7 @@ namespace RustToDust.Ymir
{
PendingExternalImpulse = true;
PreStepHadUpwardImpulse = true;
BlastArcMaxVy = InExternalBlastArc ? MathF.Max(BlastArcMaxVy, vel.Y) : vel.Y;
InExternalBlastArc = true;
}
@ -422,6 +428,7 @@ namespace RustToDust.Ymir
IsAirborne = true;
PendingExternalImpulse = hasUpwardBlast;
PreStepHadUpwardImpulse = hasUpwardBlast;
BlastArcMaxVy = hasUpwardBlast ? vel.Y : 0f;
InExternalBlastArc = hasUpwardBlast;
}
return;
@ -689,11 +696,15 @@ namespace RustToDust.Ymir
ws.PreStepHadUpwardImpulse = externalImpulse;
if (externalImpulse)
{
ws.BlastArcMaxVy = ws.InExternalBlastArc
? MathF.Max(ws.BlastArcMaxVy, vel.Y)
: vel.Y;
ws.InExternalBlastArc = true;
}
else if (ws.Grounded)
{
ws.InExternalBlastArc = false;
ws.BlastArcMaxVy = 0f;
}
ws.PendingExternalImpulse = false;
ws.PrevHorizVel = new Vector3(vel.X, 0f, vel.Z);
@ -824,9 +835,13 @@ namespace RustToDust.Ymir
}
else
{
if (!airborneImpulse && !ws.InExternalBlastArc && targetVy > 9.45f)
if (!airborneImpulse)
{
targetVy = 9.45f;
float maxCapVy = ws.InExternalBlastArc ? MathF.Max(ws.BlastArcMaxVy, 9.45f) : 9.45f;
if (targetVy > maxCapVy)
{
targetVy = maxCapVy;
}
}
view.ForceX[lane] = 0f;
view.ForceY[lane] = 0f;
@ -1110,29 +1125,6 @@ namespace RustToDust.Ymir
ws.DidStepUp = false;
}
// 1b. Suppress spurious Box3D curb/corner solver launch when not on an explicit external blast
if (!ws.PreStepHadUpwardImpulse && !ws.InExternalBlastArc && vel.Y > 0.25f)
{
Vector3 curTerrN = WalkerState.SampleTerrainNormal(terrain, pos.X, pos.Z);
Vector3 slopeN = ws.GroundNormal.Y >= 0.45f ? ws.GroundNormal : curTerrN;
float rawSlopeVy = slopeN.Y >= 0.45f ? -(vel.X * slopeN.X + vel.Z * slopeN.Z) / slopeN.Y : 0f;
float curTerrY = terrain.SampleHeight(pos.X, pos.Z);
float curCenterY = curTerrY + halfLength + radius * Math.Clamp(1f / MathF.Max(0.45f, curTerrN.Y), 1f, 1.25f);
float maxSlopeVy = (ws.WasGrounded || ws.Grounded)
? Math.Clamp(rawSlopeVy + 0.45f, 0.25f, 9.45f)
: 0.25f;
if (vel.Y > maxSlopeVy)
{
vel.Y = maxSlopeVy;
world.SetBodyMotion(
body,
position: (pos.X, pos.Y, pos.Z),
rotation: (qYaw.X, qYaw.Y, qYaw.Z, qYaw.W),
linearVelocity: (vel.X, vel.Y, vel.Z),
angularVelocity: (0f, yawRate, 0f));
}
}
// 2. Reground (step-down <= 0.75 m across curbs/dunes without launching)
float groundMinNy = ws.WasGrounded ? 0.642788f : WalkerState.MaxCliffGuardNormalY;
if (!steppedThisTick && ws.WasGrounded && !ws.PreStepHadUpwardImpulse)
@ -1266,37 +1258,24 @@ namespace RustToDust.Ymir
terrGround = gTerrN.Y >= groundMinNy && pos.Y <= gTerrCenterY + 0.18f;
}
ws.Grounded = (steppedThisTick || staticGround || terrGround) &&
!(ws.PreStepHadUpwardImpulse && vel.Y > 0.25f) &&
(ws.WasGrounded || vel.Y <= 0.25f || (!ws.PreStepHadUpwardImpulse && !ws.InExternalBlastArc));
if (staticGround)
bool onGroundContact = steppedThisTick || staticGround || terrGround;
Vector3 slopeN = staticGround ? staticNorm : gTerrN;
if (slopeN.Y < 0.45f)
{
ws.GroundNormal = staticNorm;
}
else if (terrGround)
{
ws.GroundNormal = gTerrN;
}
else
{
ws.GroundNormal = gTerrN;
slopeN = gTerrN;
}
float rawSlopeVy = slopeN.Y >= 0.45f ? -(vel.X * slopeN.X + vel.Z * slopeN.Z) / slopeN.Y : 0f;
float maxAllowedSlopeVy = (onGroundContact || ws.WasGrounded)
? Math.Clamp(rawSlopeVy + 0.45f, 0.25f, 9.45f)
: 0.25f;
if (ws.Grounded && !ws.PreStepHadUpwardImpulse)
if (ws.InExternalBlastArc)
{
ws.InExternalBlastArc = false;
}
if (!ws.PreStepHadUpwardImpulse && !ws.InExternalBlastArc && vel.Y > 0.25f)
{
Vector3 slopeN = ws.GroundNormal.Y >= 0.45f ? ws.GroundNormal : gTerrN;
float rawSlopeVy = slopeN.Y >= 0.45f ? -(vel.X * slopeN.X + vel.Z * slopeN.Z) / slopeN.Y : 0f;
float maxSlopeVy = (ws.Grounded || ws.WasGrounded)
? Math.Clamp(rawSlopeVy + 0.45f, 0.25f, 9.45f)
: 0.25f;
if (vel.Y > maxSlopeVy)
ws.BlastArcMaxVy -= WalkerState.ArenaGravity * dt;
float blastCapVy = MathF.Max(ws.BlastArcMaxVy, maxAllowedSlopeVy);
if (vel.Y > blastCapVy)
{
vel.Y = maxSlopeVy;
vel.Y = blastCapVy;
world.SetBodyMotion(
body,
position: (pos.X, pos.Y, pos.Z),
@ -1304,6 +1283,32 @@ namespace RustToDust.Ymir
linearVelocity: (vel.X, vel.Y, vel.Z),
angularVelocity: (0f, yawRate, 0f));
}
if (!ws.PreStepHadUpwardImpulse && vel.Y <= maxAllowedSlopeVy + 0.5f)
{
ws.InExternalBlastArc = false;
ws.BlastArcMaxVy = 0f;
}
}
else if (!ws.PreStepHadUpwardImpulse && vel.Y > maxAllowedSlopeVy)
{
vel.Y = maxAllowedSlopeVy;
world.SetBodyMotion(
body,
position: (pos.X, pos.Y, pos.Z),
rotation: (qYaw.X, qYaw.Y, qYaw.Z, qYaw.W),
linearVelocity: (vel.X, vel.Y, vel.Z),
angularVelocity: (0f, yawRate, 0f));
}
ws.Grounded = onGroundContact &&
!(ws.PreStepHadUpwardImpulse && vel.Y > 0.25f) &&
(ws.WasGrounded || vel.Y <= 0.25f || (!ws.PreStepHadUpwardImpulse && !ws.InExternalBlastArc));
ws.GroundNormal = staticGround ? staticNorm : gTerrN;
if (ws.Grounded && !ws.PreStepHadUpwardImpulse)
{
ws.InExternalBlastArc = false;
ws.BlastArcMaxVy = 0f;
}
ws.PostStepVelY = vel.Y;
@ -1493,7 +1498,7 @@ namespace RustToDust.Ymir
? carriedFoot + diff * (maxLocalRetract / diffLen)
: targetAirSole;
ProjectSoleAboveGroundWithinReach(hipAirW, ankleH, maxAirReach * 1.045f, terrain, world, comPos.Y + 0.8f, airClearance, ref nextSole, out Vector3 clampedAirN);
ProjectSoleAboveGroundWithinReach(hipAirW, comPos, ankleH, maxAirReach * 1.045f, terrain, world, comPos.Y + 0.8f, airClearance, ref nextSole, out Vector3 clampedAirN);
Vector3 nextAnk = nextSole + clampedAirN * ankleH;
Vector3 airD = nextAnk - hipAirW;
float airDLen = airD.Length();
@ -1501,9 +1506,22 @@ namespace RustToDust.Ymir
if (airDLen > hardAirReach && airDLen > 1e-5f)
{
nextSole = (hipAirW + airD * (hardAirReach / airDLen)) - clampedAirN * ankleH;
ProjectSoleAboveGroundWithinReach(hipAirW, ankleH, hardAirReach, terrain, world, comPos.Y + 0.8f, airClearance, ref nextSole, out clampedAirN);
ProjectSoleAboveGroundWithinReach(hipAirW, comPos, ankleH, hardAirReach, terrain, world, comPos.Y + 0.8f, airClearance, ref nextSole, out clampedAirN);
}
Vector3 nextNorm = clampedAirN;
Vector3 preAirSole = i switch { 0 => preTickSole0, 1 => preTickSole1, 2 => preTickSole2, _ => preTickSole3 };
Vector3 airStepDelta = nextSole - preAirSole;
float maxAirTickStep = 1.56f * MathF.Max(1f, scale);
if (airStepDelta.Length() > maxAirTickStep && airStepDelta.LengthSquared() > 1e-10f)
{
nextSole = preAirSole + Vector3.Normalize(airStepDelta) * maxAirTickStep;
Vector3 cappedAnk = nextSole + nextNorm * ankleH;
float cappedDist = (cappedAnk - hipAirW).Length();
if (cappedDist > hardAirReach && cappedDist > 1e-5f)
{
nextSole = (hipAirW + (cappedAnk - hipAirW) * (hardAirReach / cappedDist)) - nextNorm * ankleH;
}
}
ws.FootSole[i] = nextSole;
ws.FootNormal[i] = Vector3.Normalize(Vector3.Lerp(ws.FootNormal[i], nextNorm, Math.Clamp(dt * 8f, 0f, 1f)));
@ -1840,6 +1858,25 @@ namespace RustToDust.Ymir
float tx = nominal.X + stepOffset.X;
float tz = nominal.Z + stepOffset.Y;
if (geom.IsArachnidUp)
{
Vector3 hipPredA = predCom + Vector3.Transform(geom.Legs[i].HipInCom * scale, predYaw);
float hdx = tx - hipPredA.X;
float hdz = tz - hipPredA.Z;
float hDist = MathF.Sqrt(hdx * hdx + hdz * hdz);
float minRadial = 0.58f * scale;
if (hDist < minRadial)
{
Vector3 f0W = Vector3.Transform(geom.Legs[i].LegFwd0, predYaw);
f0W.Y = 0f;
Vector2 outDir = hDist > 1e-4f
? new Vector2(hdx / hDist, hdz / hDist)
: (f0W.LengthSquared() > 1e-5f ? Vector2.Normalize(new Vector2(f0W.X, f0W.Z)) : Vector2.UnitY);
tx = hipPredA.X + outDir.X * minRadial;
tz = hipPredA.Z + outDir.Y * minRadial;
}
}
if (n == 2)
{
float minLat = 0.22f * scale;
@ -1935,6 +1972,23 @@ namespace RustToDust.Ymir
float clampedUnderY = MathF.Min(underHit.SurfaceY, ws.FootSole[i].Y + maxSwingStep * 0.90f);
float minGround = clampedUnderY + 0.10f * scale * legEnv;
Vector3 desiredSole = new(sx, MathF.Max(syBase + arcLift, minGround), sz);
if (geom.IsArachnidUp)
{
float hdx = desiredSole.X - curHip.X;
float hdz = desiredSole.Z - curHip.Z;
float hDist = MathF.Sqrt(hdx * hdx + hdz * hdz);
float minSwingRadial = 0.58f * scale;
if (hDist < minSwingRadial)
{
Vector3 f0W = Vector3.Transform(geom.Legs[i].LegFwd0, qYaw);
f0W.Y = 0f;
Vector2 outDir = hDist > 1e-4f
? new Vector2(hdx / hDist, hdz / hDist)
: (f0W.LengthSquared() > 1e-5f ? Vector2.Normalize(new Vector2(f0W.X, f0W.Z)) : Vector2.UnitY);
desiredSole.X = curHip.X + outDir.X * minSwingRadial;
desiredSole.Z = curHip.Z + outDir.Y * minSwingRadial;
}
}
Vector3 swingStep = desiredSole - ws.FootSole[i];
float swingStepLen = swingStep.Length();
if (swingStepLen > maxSwingStep && swingStepLen > 1e-5f)
@ -2223,17 +2277,18 @@ namespace RustToDust.Ymir
var gStep = SampleGroundAt(terrain, world, nextSole.X, nextSole.Z, comPos.Y + 0.8f);
if (gStep.SurfaceY <= oldSole.Y + maxUnplantStep * 0.90f && nextSole.Y < gStep.SurfaceY)
{
ProjectSoleAboveGroundWithinReach(hipTotalW, ankleH, maxReach, terrain, world, comPos.Y + 0.8f, 0f, ref nextSole, out Vector3 pNorm);
ProjectSoleAboveGroundWithinReach(hipTotalW, comPos, ankleH, maxReach, terrain, world, comPos.Y + 0.8f, 0f, ref nextSole, out Vector3 pNorm);
ws.FootNormal[i] = pNorm;
}
Vector3 nextDelta = (nextSole + ws.FootNormal[i] * ankleH) - hipTotalW;
float nextDist = nextDelta.Length();
float unplantMaxR = maxReach * 1.055f;
float unplantMaxR = maxReach * 1.025f + 0.029f;
if (nextDist > unplantMaxR && nextDist > 1e-5f)
{
Vector3 uAnk = hipTotalW + nextDelta * (unplantMaxR / nextDist);
nextSole = uAnk - ws.FootNormal[i] * ankleH;
ProjectSoleAboveGroundWithinReach(hipTotalW, ankleH, unplantMaxR, terrain, world, comPos.Y + 0.8f, 0f, ref nextSole, out _);
ProjectSoleAboveGroundWithinReach(hipTotalW, comPos, ankleH, unplantMaxR, terrain, world, comPos.Y + 0.8f, 0f, ref nextSole, out Vector3 pNorm2);
ws.FootNormal[i] = pNorm2;
}
ws.FootSole[i] = nextSole;
}
@ -2249,34 +2304,61 @@ namespace RustToDust.Ymir
bool justLifted = ws.Grounded && (i switch { 0 => jl0, 1 => jl1, 2 => jl2, _ => jl3 });
float maxRetract = 0.22f * MathF.Max(1f, scale);
float targetDist = justLifted
? MathF.Min(maxReach * 1.06f, MathF.Max(maxReach, dist - maxRetract))
? MathF.Min(maxReach * 1.025f + 0.029f, MathF.Max(maxReach, dist - maxRetract))
: maxReach;
Vector3 clampedAnkle = hipTotalW + delta * (targetDist / dist);
Vector3 clampedSole = clampedAnkle - ws.FootNormal[i] * ankleH;
ProjectSoleAboveGroundWithinReach(hipTotalW, ankleH, targetDist, terrain, world, comPos.Y + 0.8f, 0f, ref clampedSole, out _);
ProjectSoleAboveGroundWithinReach(hipTotalW, comPos, ankleH, targetDist, terrain, world, comPos.Y + 0.8f, 0f, ref clampedSole, out Vector3 pNorm3);
ws.FootNormal[i] = pNorm3;
ws.FootSole[i] = clampedSole;
}
}
if (ws.Grounded && !ws.WasAirborne)
if ((comPos - ws.CurrSnap.ComPos).LengthSquared() <= 16f)
{
bool wasPlanted = i switch { 0 => preTickPlanted0, 1 => preTickPlanted1, 2 => preTickPlanted2, _ => preTickPlanted3 };
if (wasPlanted && !ws.Planted[i])
Vector3 startS = i switch { 0 => preTickSole0, 1 => preTickSole1, 2 => preTickSole2, _ => preTickSole3 };
if (ws.Grounded && !ws.WasAirborne)
{
Vector3 startS = i switch { 0 => preTickSole0, 1 => preTickSole1, 2 => preTickSole2, _ => preTickSole3 };
Vector3 liftDelta = ws.FootSole[i] - startS;
float liftLen = liftDelta.Length();
float maxLiftoffMove = 0.31f * MathF.Max(1f, scale);
if (liftLen > maxLiftoffMove && liftLen > 1e-5f)
bool wasPlanted = i switch { 0 => preTickPlanted0, 1 => preTickPlanted1, 2 => preTickPlanted2, _ => preTickPlanted3 };
if (wasPlanted && !ws.Planted[i])
{
Vector3 cappedLift = startS + liftDelta * (maxLiftoffMove / liftLen);
Vector3 liftAnk = cappedLift + ws.FootNormal[i] * ankleH;
if ((liftAnk - hipTotalW).Length() <= maxReach * 1.06f)
Vector3 liftDelta = ws.FootSole[i] - startS;
float liftLen = liftDelta.Length();
float maxLiftoffMove = 0.34f * MathF.Max(1f, scale);
if (liftLen > maxLiftoffMove && liftLen > 1e-5f)
{
ws.FootSole[i] = cappedLift;
Vector3 cappedLift = startS + liftDelta * (maxLiftoffMove / liftLen);
Vector3 liftDeltaHip = (cappedLift + ws.FootNormal[i] * ankleH) - hipTotalW;
float liftHipDist = liftDeltaHip.Length();
float liftMaxR = maxReach * 1.025f + 0.029f;
if (liftHipDist > liftMaxR && liftHipDist > 1e-5f)
{
cappedLift = (hipTotalW + liftDeltaHip * (liftMaxR / liftHipDist)) - ws.FootNormal[i] * ankleH;
ProjectSoleAboveGroundWithinReach(hipTotalW, comPos, ankleH, liftMaxR, terrain, world, comPos.Y + 0.8f, 0f, ref cappedLift, out Vector3 liftNorm);
ws.FootNormal[i] = liftNorm;
}
if ((cappedLift - startS).Length() < liftLen)
{
ws.FootSole[i] = cappedLift;
}
}
}
}
Vector3 tickDelta = ws.FootSole[i] - startS;
float tickLen = tickDelta.Length();
float maxTickDisp = 1.56f * MathF.Max(1f, scale);
if (tickLen > maxTickDisp && tickLen > 1e-5f)
{
Vector3 capped = startS + tickDelta * (maxTickDisp / tickLen);
Vector3 cappedAnk = capped + ws.FootNormal[i] * ankleH;
float cappedDist = (cappedAnk - hipTotalW).Length();
if (cappedDist > maxReach * 1.025f + 0.029f && cappedDist > 1e-5f)
{
capped = (hipTotalW + (cappedAnk - hipTotalW) * (maxReach / cappedDist)) - ws.FootNormal[i] * ankleH;
}
ws.FootSole[i] = capped;
}
}
}
@ -2305,7 +2387,9 @@ namespace RustToDust.Ymir
Vector3 hipWorld = comPos + pelvisWorldShift + Vector3.Transform(geom.Legs[i].HipInCom * scale, qTotal);
Vector3 ankleWorld = ws.FootSole[i] + ws.FootNormal[i] * (geom.Legs[i].AnkleH * scale);
float legToePitch = ws.Planted[i] ? 0f : swingToePitch;
WalkerLegAngles target = SolveLegTargetAngles(geom, scale, i, hipWorld, qTotal, ankleWorld, ws.FootNormal[i], legToePitch);
WalkerLegAngles target = SolveLegTargetAngles(
geom, scale, i, hipWorld, qTotal, ankleWorld, ws.FootNormal[i], legToePitch,
ws.Actuators[i].Theta.HipRoll, hasPrevCoxaYaw: true);
bool planted = ws.Planted[i];
bool wasPlanted = i switch { 0 => preTickPlanted0, 1 => preTickPlanted1, 2 => preTickPlanted2, _ => preTickPlanted3 };
@ -2337,7 +2421,7 @@ namespace RustToDust.Ymir
for (int sub = 0; sub < 4; sub++)
{
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.HipRoll, ref act.Omega.HipRoll, target.HipRoll, refHipRoll, kp, kd, tauMax, limbI, 0f, subDt, geom.IsArachnidUp ? float.PositiveInfinity : 3.08f);
StepDof(ref act.Theta.KneeFlex, ref act.Omega.KneeFlex, target.KneeFlex, refKnee, kpKnee, kdKnee, tauKnee, limbI, 0f, subDt);
if (geom.IsDigitigrade)
{
@ -2350,6 +2434,11 @@ namespace RustToDust.Ymir
}
StepDof(ref act.Theta.AnklePitch, ref act.Omega.AnklePitch, target.AnklePitch, refAnkle, kp * 1.35f, kd * 1.16f, tauAnkleMax, limbI, 0f, subDt);
}
if (geom.IsArachnidUp)
{
while (act.Theta.HipRoll > MathF.PI) act.Theta.HipRoll -= MathF.Tau;
while (act.Theta.HipRoll <= -MathF.PI) act.Theta.HipRoll += MathF.Tau;
}
ws.PrevTargetAngles[i] = target;
if (!ws.Grounded || !planted)
@ -2380,12 +2469,14 @@ namespace RustToDust.Ymir
float tauMax,
float inertia,
float recoilTorque,
float dt)
float dt,
float maxAbsAngle = 3.08f)
{
float err = target - theta;
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);
float next = theta + omega * dt;
theta = float.IsFinite(maxAbsAngle) ? Math.Clamp(next, -maxAbsAngle, maxAbsAngle) : next;
}
private static bool IsInGroup(int legCount, int legIdx, int group)
@ -2534,13 +2625,14 @@ namespace RustToDust.Ymir
: hipWorld - new Vector3(0f, maxReach, 0f);
var underSphere = SampleGroundAt(terrain, world, clampedAnkle.X, clampedAnkle.Z, referenceMaxY);
Vector3 sphereSole = clampedAnkle - underSphere.Normal * ankleH;
ProjectSoleAboveGroundWithinReach(hipWorld, ankleH, maxReach, terrain, world, referenceMaxY, 0f, ref sphereSole, out normal);
ProjectSoleAboveGroundWithinReach(hipWorld, chassisCenterWorld, ankleH, maxReach, terrain, world, referenceMaxY, 0f, ref sphereSole, out normal);
sole = sphereSole;
return true;
}
private static void ProjectSoleAboveGroundWithinReach(
Vector3 hipWorld,
Vector3 chassisCenterWorld,
float ankleH,
float maxReach,
TerrainField terrain,
@ -2550,79 +2642,276 @@ namespace RustToDust.Ymir
ref Vector3 sole,
out Vector3 normal)
{
Vector3 origSole = sole;
var under = SampleGroundAt(terrain, world, sole.X, sole.Z, referenceMaxY);
float minY = under.SurfaceY + clearance;
if (sole.Y >= minY)
float candY = MathF.Max(origSole.Y, minY);
Vector3 candAnk = new Vector3(origSole.X, candY, origSole.Z) + under.Normal * ankleH;
if (MathF.Abs(candAnk.Y - hipWorld.Y) < maxReach * 0.98f && (candAnk - hipWorld).Length() <= maxReach)
{
sole.Y = candY;
normal = under.Normal;
return;
}
sole.Y = minY;
for (int iter = 0; iter < 6; iter++)
if (MathF.Abs((minY + under.Normal.Y * ankleH) - hipWorld.Y) < maxReach * 0.98f)
{
Vector3 ank = sole + under.Normal * ankleH;
Vector3 d = ank - hipWorld;
if (d.Length() <= maxReach)
Vector3 workSole = new(origSole.X, candY, origSole.Z);
WalkableSurfaceHit workHit = under;
bool hitWall = false;
for (int iter = 0; iter < 6; iter++)
{
break;
}
Vector3 ank = workSole + workHit.Normal * ankleH;
if ((ank - hipWorld).Length() <= maxReach)
{
sole = workSole;
normal = workHit.Normal;
return;
}
float dy = ank.Y - hipWorld.Y;
if (MathF.Abs(dy) < maxReach * 0.995f)
{
float maxHoriz = MathF.Sqrt(MathF.Max(0.0004f, maxReach * maxReach - dy * dy)) * 0.995f;
float dy = ank.Y - hipWorld.Y;
if (MathF.Abs(dy) >= maxReach * 0.98f)
{
hitWall = true;
break;
}
float maxHoriz = MathF.Sqrt(MathF.Max(0.0004f, maxReach * maxReach - dy * dy)) * 0.992f;
float dx = ank.X - hipWorld.X;
float dz = ank.Z - hipWorld.Z;
float hDist = MathF.Sqrt(dx * dx + dz * dz);
if (hDist > maxHoriz && hDist > 1e-4f)
if (hDist <= maxHoriz || hDist < 1e-4f)
{
float k = maxHoriz / hDist;
sole.X = hipWorld.X + dx * k - under.Normal.X * ankleH;
sole.Z = hipWorld.Z + dz * k - under.Normal.Z * ankleH;
under = SampleGroundAt(terrain, world, sole.X, sole.Z, referenceMaxY);
sole.Y = MathF.Max(sole.Y, under.SurfaceY + clearance);
continue;
break;
}
break;
float k = maxHoriz / hDist;
workSole.X = hipWorld.X + dx * k - workHit.Normal.X * ankleH;
workSole.Z = hipWorld.Z + dz * k - workHit.Normal.Z * ankleH;
workHit = SampleGroundAt(terrain, world, workSole.X, workSole.Z, referenceMaxY);
float wMinY = workHit.SurfaceY + clearance;
float wCandY = MathF.Max(origSole.Y, wMinY);
if (MathF.Abs((wCandY + workHit.Normal.Y * ankleH) - hipWorld.Y) >= maxReach * 0.98f)
{
hitWall = true;
break;
}
workSole.Y = wCandY;
}
else
Vector3 checkAnk = workSole + workHit.Normal * ankleH;
if (!hitWall && workSole.Y >= workHit.SurfaceY + clearance && (checkAnk - hipWorld).Length() <= maxReach)
{
// Ground at sole XZ lies above hip upper sphere: step horizontally inward toward hipWorld
sole.X += (hipWorld.X - sole.X) * 0.45f;
sole.Z += (hipWorld.Z - sole.Z) * 0.45f;
under = SampleGroundAt(terrain, world, sole.X, sole.Z, referenceMaxY);
sole.Y = under.SurfaceY + clearance;
sole = workSole;
normal = workHit.Normal;
return;
}
}
under = SampleGroundAt(terrain, world, sole.X, sole.Z, referenceMaxY);
if (sole.Y < under.SurfaceY + clearance)
// Cliff / building wall beside hip or horizontal overrun: pull radially inward toward hipWorld, then chassisCenterWorld.
Vector3 bestFallbackAnk = candAnk;
float bestFallbackDist = MathF.Abs(candAnk.Y - hipWorld.Y) < maxReach * 0.98f
? (candAnk - hipWorld).Length()
: float.PositiveInfinity;
if (TryPullSoleInward(origSole, hipWorld, hipWorld, ankleH, maxReach, terrain, world, referenceMaxY, clearance, 8, ref bestFallbackAnk, ref bestFallbackDist, out Vector3 foundSole, out Vector3 foundNorm) ||
TryPullSoleInward(origSole, chassisCenterWorld, hipWorld, ankleH, maxReach, terrain, world, referenceMaxY, clearance, 10, ref bestFallbackAnk, ref bestFallbackDist, out foundSole, out foundNorm))
{
sole.Y = under.SurfaceY + clearance;
sole = foundSole;
normal = foundNorm;
return;
}
Vector3 finalAnk = sole + under.Normal * ankleH;
if ((finalAnk - hipWorld).Length() > maxReach)
// Sheer overhang/airborne fallback: clamp on 3D reach sphere without snapping up unreachable walls.
Vector3 sphDelta = (float.IsFinite(bestFallbackDist) ? bestFallbackAnk : candAnk) - hipWorld;
float sphDist = sphDelta.Length();
Vector3 sphAnk = sphDist > 1e-5f
? hipWorld + sphDelta * ((maxReach * 0.995f) / sphDist)
: hipWorld - new Vector3(0f, maxReach * 0.995f, 0f);
var postUnder = SampleGroundAt(terrain, world, sphAnk.X, sphAnk.Z, referenceMaxY);
Vector3 sphSole = sphAnk - postUnder.Normal * ankleH;
float postMinY = postUnder.SurfaceY + clearance;
if (sphSole.Y < postMinY)
{
float dy = finalAnk.Y - hipWorld.Y;
if (MathF.Abs(dy) < maxReach * 0.995f)
Vector3 raisedAnk = new Vector3(sphSole.X, postMinY, sphSole.Z) + postUnder.Normal * ankleH;
if ((raisedAnk - hipWorld).Length() <= maxReach)
{
float maxHoriz = MathF.Sqrt(MathF.Max(0.0004f, maxReach * maxReach - dy * dy)) * 0.995f;
float dx = finalAnk.X - hipWorld.X;
float dz = finalAnk.Z - hipWorld.Z;
float hDist = MathF.Sqrt(dx * dx + dz * dz);
if (hDist > maxHoriz && hDist > 1e-4f)
sphSole.Y = postMinY;
}
}
sole = sphSole;
normal = postUnder.Normal;
}
private static bool TryPullSoleInward(
Vector3 origSole,
Vector3 pullTargetXz,
Vector3 hipWorld,
float ankleH,
float maxReach,
TerrainField terrain,
Box3DSoaWorld? world,
float referenceMaxY,
float clearance,
int steps,
ref Vector3 bestFallbackAnk,
ref float bestFallbackDist,
out Vector3 outSole,
out Vector3 outNorm)
{
float spanX = pullTargetXz.X - origSole.X;
float spanZ = pullTargetXz.Z - origSole.Z;
if (spanX * spanX + spanZ * spanZ < 1e-6f)
{
outSole = origSole;
outNorm = Vector3.UnitY;
return false;
}
float prevT = 0f;
for (int s = 1; s <= steps; s++)
{
float t = s / (float)steps;
float sx = origSole.X + spanX * t;
float sz = origSole.Z + spanZ * t;
if (TryEvaluateGroundPointInReach(origSole.Y, sx, sz, hipWorld, ankleH, maxReach, terrain, world, referenceMaxY, clearance, out Vector3 candSole, out Vector3 candNorm, out Vector3 candAnk, out float candDist))
{
float lo = prevT;
float hi = t;
Vector3 bestSole = candSole;
Vector3 bestNorm = candNorm;
for (int b = 0; b < 3; b++)
{
float k = maxHoriz / hDist;
sole.X = hipWorld.X + dx * k - under.Normal.X * ankleH;
sole.Z = hipWorld.Z + dz * k - under.Normal.Z * ankleH;
var postUnder = SampleGroundAt(terrain, world, sole.X, sole.Z, referenceMaxY);
sole.Y = MathF.Max(sole.Y, postUnder.SurfaceY + clearance);
under = postUnder;
float mid = 0.5f * (lo + hi);
float mx = origSole.X + spanX * mid;
float mz = origSole.Z + spanZ * mid;
if (TryEvaluateGroundPointInReach(origSole.Y, mx, mz, hipWorld, ankleH, maxReach, terrain, world, referenceMaxY, clearance, out Vector3 mSole, out Vector3 mNorm, out _, out _))
{
hi = mid;
bestSole = mSole;
bestNorm = mNorm;
}
else
{
lo = mid;
}
}
outSole = bestSole;
outNorm = bestNorm;
return true;
}
if (candDist < bestFallbackDist)
{
bestFallbackDist = candDist;
bestFallbackAnk = candAnk;
}
prevT = t;
}
outSole = origSole;
outNorm = Vector3.UnitY;
return false;
}
private static bool TryEvaluateGroundPointInReach(
float origSoleY,
float sx,
float sz,
Vector3 hipWorld,
float ankleH,
float maxReach,
TerrainField terrain,
Box3DSoaWorld? world,
float referenceMaxY,
float clearance,
out Vector3 outSole,
out Vector3 outNorm,
out Vector3 outAnk,
out float outDist)
{
var sh = SampleGroundAt(terrain, world, sx, sz, referenceMaxY);
float sMinY = sh.SurfaceY + clearance;
float sY = MathF.Max(origSoleY, sMinY);
Vector3 sAnk = new Vector3(sx, sY, sz) + sh.Normal * ankleH;
float dist = (sAnk - hipWorld).Length();
outSole = new Vector3(sx, sY, sz);
outNorm = sh.Normal;
outAnk = sAnk;
outDist = dist;
if (MathF.Abs(sAnk.Y - hipWorld.Y) >= maxReach * 0.98f)
{
if (sMinY < sY && MathF.Abs((sMinY + sh.Normal.Y * ankleH) - hipWorld.Y) < maxReach * 0.98f)
{
float hSq = (sAnk.X - hipWorld.X) * (sAnk.X - hipWorld.X) + (sAnk.Z - hipWorld.Z) * (sAnk.Z - hipWorld.Z);
if (hSq < maxReach * maxReach)
{
float remY = MathF.Sqrt(maxReach * maxReach - hSq) * 0.995f;
sY = MathF.Max(sMinY, MathF.Min(sY, hipWorld.Y + remY - sh.Normal.Y * ankleH));
sAnk = new Vector3(sx, sY, sz) + sh.Normal * ankleH;
dist = (sAnk - hipWorld).Length();
outSole = new Vector3(sx, sY, sz);
outAnk = sAnk;
outDist = dist;
}
}
else
{
return false;
}
}
if (dist > maxReach && sY > sMinY)
{
float hSq = (sAnk.X - hipWorld.X) * (sAnk.X - hipWorld.X) + (sAnk.Z - hipWorld.Z) * (sAnk.Z - hipWorld.Z);
if (hSq < maxReach * maxReach)
{
float remY = MathF.Sqrt(maxReach * maxReach - hSq) * 0.995f;
sY = MathF.Max(sMinY, MathF.Min(sY, hipWorld.Y + remY - sh.Normal.Y * ankleH));
sAnk = new Vector3(sx, sY, sz) + sh.Normal * ankleH;
dist = (sAnk - hipWorld).Length();
outSole = new Vector3(sx, sY, sz);
outAnk = sAnk;
outDist = dist;
}
}
if (dist <= maxReach)
{
return true;
}
float dy = sAnk.Y - hipWorld.Y;
if (MathF.Abs(dy) < maxReach * 0.98f)
{
float maxHoriz = MathF.Sqrt(MathF.Max(0.0004f, maxReach * maxReach - dy * dy)) * 0.992f;
float dx = sAnk.X - hipWorld.X;
float dz = sAnk.Z - hipWorld.Z;
float hDist = MathF.Sqrt(dx * dx + dz * dz);
if (hDist > maxHoriz && hDist > 1e-4f)
{
float hk = maxHoriz / hDist;
float hx = hipWorld.X + dx * hk - sh.Normal.X * ankleH;
float hz = hipWorld.Z + dz * hk - sh.Normal.Z * ankleH;
var hh = SampleGroundAt(terrain, world, hx, hz, referenceMaxY);
float hMinY = hh.SurfaceY + clearance;
float hy = MathF.Max(origSoleY, hMinY);
if (MathF.Abs((hMinY + hh.Normal.Y * ankleH) - hipWorld.Y) < maxReach * 0.98f)
{
Vector3 hAnk = new Vector3(hx, hy, hz) + hh.Normal * ankleH;
float hCandDist = (hAnk - hipWorld).Length();
if (hCandDist <= maxReach)
{
outSole = new Vector3(hx, hy, hz);
outNorm = hh.Normal;
outAnk = hAnk;
outDist = hCandDist;
return true;
}
}
}
}
normal = under.Normal;
return false;
}
public static WalkerLegAngles SolveLegTargetAngles(
@ -2633,7 +2922,9 @@ namespace RustToDust.Ymir
Quaternion qBody,
Vector3 ankleWorld,
Vector3 footNormalWorld,
float swingToePitch)
float swingToePitch,
float prevCoxaYaw = 0f,
bool hasPrevCoxaYaw = false)
{
var leg = geom.Legs[legIdx];
Quaternion qInv = Quaternion.Conjugate(qBody);
@ -2650,8 +2941,16 @@ 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 planarLenSq = dx * dx + dz * dz;
float coxaYaw = planarLenSq > 1e-6f
? MathF.Atan2(dx, dz)
: (hasPrevCoxaYaw ? prevCoxaYaw : 0f);
if (hasPrevCoxaYaw)
{
while (coxaYaw - prevCoxaYaw > MathF.PI) coxaYaw -= MathF.Tau;
while (coxaYaw - prevCoxaYaw < -MathF.PI) coxaYaw += MathF.Tau;
}
float planarOut = MathF.Max(0.02f * scale, dx * MathF.Sin(coxaYaw) + dz * MathF.Cos(coxaYaw));
float planarUp = dy;
float d = Math.Clamp(
MathF.Sqrt(planarOut * planarOut + planarUp * planarUp),
@ -2659,7 +2958,7 @@ namespace RustToDust.Ymir
leg.MaxLegReach * scale);
float l1 = leg.L1 * scale;
float l2 = leg.L2 * scale;
float baseElev = MathF.Atan2(planarUp, MathF.Max(0.05f * scale, planarOut));
float baseElev = MathF.Atan2(planarUp, MathF.Max(0.02f * scale, planarOut));
float cosAlpha = Math.Clamp((l1 * l1 + d * d - l2 * l2) / (2f * l1 * d), -1f, 1f);
float alpha = MathF.Acos(cosAlpha);
float cosKnee = Math.Clamp((l1 * l1 + l2 * l2 - d * d) / (2f * l1 * l2), -1f, 1f);

View file

@ -2017,7 +2017,7 @@ namespace RustToDust.Tests
Vector3 ankleWorld = ws.FootSole[i] + ws.FootNormal[i] * (ws.Geom.Legs[i].AnkleH * ws.GeomScale);
float dist3D = Vector3.Distance(ankleWorld, hipWorld);
float maxReach = ws.Geom.Legs[i].MaxLegReach * ws.GeomScale;
float reachLimit = ws.Planted[i] ? maxReach + 0.05f : maxReach * 1.07f + 0.05f;
float reachLimit = ws.Planted[i] ? maxReach + 0.05f : maxReach * 1.02f + 0.03f;
Assert.True(dist3D <= reachLimit,
$"{spec.Id} Sion steep slope tick {t} leg {i}: 3D reach overflow {dist3D:F3} > {reachLimit:F3}");
@ -2035,13 +2035,12 @@ namespace RustToDust.Tests
}
}
// 2. Kestrel + Spectre + ExemplarFrame sprinting across Sion curbs/hills must stay grounded with zero non-blast launches & < 1.65m foot deltas
// 2. Kestrel + Spectre + ExemplarFrame sprinting uphill at steepSite must stay grounded with zero non-blast launches & < 1.65m foot deltas
foreach (var sprintSpec in new[] { Catalog.Kestrel, Catalog.Spectre, MakeExemplarSpec() })
{
bool isSteepTest = sprintSpec.Id == "kestrel";
float startX = isSteepTest ? steepSite.X : 0f;
float startZ = isSteepTest ? steepSite.Z : -15f;
float startYaw = isSteepTest ? steepSite.Yaw : 0f;
float startX = steepSite.X;
float startZ = steepSite.Z;
float startYaw = steepSite.Yaw;
sionSession.SetContenderPose(0, startX, startZ, startYaw);
if (sprintSpec.Id != "exemplar_frame")
{
@ -2070,18 +2069,11 @@ namespace RustToDust.Tests
for (int t = 0; t < 120; t++)
{
float aimYaw = startYaw;
if (isSteepTest)
{
var (nx, ny, nz) = sionSession.State.Terrain.SampleNormal(contender.X, contender.Z);
if (ny < 0.995f) aimYaw = MathF.Atan2(-nx, -nz);
}
else
{
aimYaw = MathF.Sin(t * 0.05f) * 0.45f;
}
var (nx, ny, nz) = sionSession.State.Terrain.SampleNormal(contender.X, contender.Z);
if (ny < 0.995f) aimYaw = MathF.Atan2(-nx, -nz);
sionSession.SetHumanInput(0, new PlayerInput(
1.0f,
isSteepTest ? 0f : MathF.Sin(t * 0.07f) * 0.45f,
0f,
contender.X + 40f * MathF.Sin(aimYaw),
contender.Z + 40f * MathF.Cos(aimYaw),
false, false, false));
@ -2213,5 +2205,327 @@ namespace RustToDust.Tests
}
}
}
[Fact]
public void SoulPass3_KestrelSionUphillLowSplash_NoSlopeContactPumping_LandsCleanly()
{
using var sionSession = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true);
for (int i = 1; i < sionSession.State.Contenders.Count; i++)
{
sionSession.SetContenderPose(i, 900f + i * 16f, 900f);
}
var sion = sionSession.State.SionMap!;
(float X, float Z, float Yaw) steepSite = default;
float bestMinNy = 1f;
for (float r = 40f; r <= 950f; r += 20f)
{
for (int a = 0; a < 72; a++)
{
float ang = a * (MathF.Tau / 72f);
float x = MathF.Cos(ang) * r;
float z = MathF.Sin(ang) * r;
if (sion.IsInsideAnyBuildingXz(x, z, 14f)) continue;
var (nx, ny, nz) = sionSession.State.Terrain.SampleNormal(x, z);
if (ny >= 0.78f && ny <= 0.88f && ny < bestMinNy)
{
bestMinNy = ny;
steepSite = (x, z, MathF.Atan2(-nx, -nz));
}
}
}
sionSession.SetContenderPose(0, steepSite.X, steepSite.Z, steepSite.Yaw);
sionSession.State.SpawnChassisDrop(steepSite.X, steepSite.Z, Catalog.Kestrel);
Assert.True(sionSession.TrySwapNearbyChassis(0));
sionSession.SetContenderPose(0, steepSite.X, steepSite.Z, steepSite.Yaw);
var player = sionSession.State.Contenders[0];
var body = sionSession.GetContenderBody(player.Id)!.Value;
var ws = sionSession.GetWalkerState(true, player.Id)!;
var view = sionSession.World.View;
int lane = body.Lane;
for (int t = 0; t < 25; t++)
{
var (nx, ny, nz) = sionSession.State.Terrain.SampleNormal(player.X, player.Z);
float aimYaw = ny < 0.995f ? MathF.Atan2(-nx, -nz) : steepSite.Yaw;
sionSession.SetHumanInput(0, new PlayerInput(
1.0f, 0f,
player.X + 40f * MathF.Sin(aimYaw),
player.Z + 40f * MathF.Cos(aimYaw),
false, false, false));
sionSession.Step();
}
float preBlastVy = view.VelocityY[lane];
float mass = view.Mass[lane];
const float splashVy = 2.25f;
ws.NotifyExternalUpwardImpulse(splashVy);
sionSession.World.ApplyImpulse(lane, (0f, mass * splashVy, 0f), (view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]));
float maxVyAfterBlast = float.NegativeInfinity;
float tick1Vy = 0f;
bool regroundedAfterBlast = false;
float maxAboveSlope = 0f;
float rideH = MatchRules.GetRideHeight(Catalog.Kestrel);
for (int t = 0; t < 60; t++)
{
var (nx, ny, nz) = sionSession.State.Terrain.SampleNormal(player.X, player.Z);
float aimYaw = ny < 0.995f ? MathF.Atan2(-nx, -nz) : steepSite.Yaw;
sionSession.SetHumanInput(0, new PlayerInput(
1.0f, 0f,
player.X + 40f * MathF.Sin(aimYaw),
player.Z + 40f * MathF.Cos(aimYaw),
false, false, false));
sionSession.Step();
float vy = view.VelocityY[lane];
if (t == 0) tick1Vy = vy;
maxVyAfterBlast = MathF.Max(maxVyAfterBlast, vy);
float surfY = sionSession.QueryDropSurface(player.X, player.Z, 0f, player.Y + 1.0f).SurfaceY;
maxAboveSlope = MathF.Max(maxAboveSlope, player.Y - (surfY + rideH));
if (t > 0 && ws.Grounded) regroundedAfterBlast = true;
}
_output.WriteLine($"Kestrel Sion uphill 2.25m/s splash: preVy={preBlastVy:F2}, tick1Vy={tick1Vy:F2}, maxVy={maxVyAfterBlast:F2}, maxAboveSlope={maxAboveSlope:F2}m, landed={regroundedAfterBlast}");
Assert.True(tick1Vy > preBlastVy + 0.5f, $"Kestrel uphill 2.25 m/s blast was suppressed on tick 1 (pre={preBlastVy:F2}, tick1={tick1Vy:F2})");
Assert.True(maxVyAfterBlast <= MathF.Max(preBlastVy + splashVy, 9.45f) + 0.15f,
$"Kestrel uphill blast pumped vel.Y to {maxVyAfterBlast:F2} m/s (pre={preBlastVy:F2}, splash={splashVy:F2})");
Assert.True(maxVyAfterBlast < 12.5f, $"Kestrel uphill blast pumped to {maxVyAfterBlast:F2} m/s");
Assert.True(maxAboveSlope < 0.85f, $"Kestrel uphill blast launched {maxAboveSlope:F2}m above slope");
Assert.True(regroundedAfterBlast, "Kestrel failed to land cleanly within 60 ticks after 2.25 m/s uphill splash");
}
[Fact]
public void SoulPass3_VerticalCliffAndWall_NoWallSnapTeleport_ReachClamped()
{
// 1. Desert Bastion approaching vertical MesaWall
using (var desert = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true))
{
for (int i = 1; i < desert.State.Contenders.Count; i++)
{
desert.SetContenderPose(i, 900f + i * 16f, 900f);
}
TerrainBrush? mesa = null;
foreach (var b in desert.State.Terrain.Brushes)
{
if (b.Kind == TerrainBrushKind.Mesa && b.HeightDelta >= 6f)
{
mesa = b;
break;
}
}
Assert.True(mesa.HasValue, "Expected a Mesa brush on Desert seed 42");
var m = mesa!.Value;
float startX = m.X;
float startZ = m.Z - m.RadiusZ - 14f;
desert.SetContenderPose(0, startX, startZ, 0f);
desert.State.SpawnChassisDrop(startX, startZ, Catalog.Bastion);
Assert.True(desert.TrySwapNearbyChassis(0));
desert.SetContenderPose(0, startX, startZ, 0f);
var player = desert.State.Contenders[0];
var body = desert.GetContenderBody(player.Id)!.Value;
var ws = desert.GetWalkerState(true, player.Id)!;
var view = desert.World.View;
int lane = body.Lane;
Vector3[] prevSoles = new Vector3[ws.Geom.LegCount];
for (int i = 0; i < ws.Geom.LegCount; i++) prevSoles[i] = ws.FootSole[i];
float maxJump = 0f;
float maxSwOver = 0f;
float maxPOver = 0f;
for (int t = 0; t < 180; t++)
{
desert.SetHumanInput(0, new PlayerInput(1.0f, 0f, m.X, m.Z, false, false, false));
desert.Step();
var comPos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
var qYaw = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
var qTotal = Quaternion.Normalize(qYaw * Quaternion.CreateFromYawPitchRoll(0f, ws.LeanPitch, ws.LeanRoll));
Vector3 pelvisW = Vector3.Transform(ws.PelvisOffset, qYaw);
for (int i = 0; i < ws.Geom.LegCount; i++)
{
float jump = Vector3.Distance(ws.FootSole[i], prevSoles[i]);
if (jump > maxJump) maxJump = jump;
Vector3 hipW = comPos + pelvisW + Vector3.Transform(ws.Geom.Legs[i].HipInCom * ws.GeomScale, qTotal);
Vector3 ankW = ws.FootSole[i] + ws.FootNormal[i] * (ws.Geom.Legs[i].AnkleH * ws.GeomScale);
float dist3D = Vector3.Distance(ankW, hipW);
float maxR = ws.Geom.Legs[i].MaxLegReach * ws.GeomScale;
if (ws.Planted[i]) maxPOver = MathF.Max(maxPOver, dist3D - maxR);
else maxSwOver = MathF.Max(maxSwOver, dist3D - maxR);
float limit = ws.Planted[i] ? maxR + 0.05f : maxR * 1.02f + 0.03f;
Assert.True(dist3D <= limit, $"Desert Bastion MesaWall tick {t} leg {i}: reach {dist3D:F3} > {limit:F3}");
Assert.True(jump < 1.60f, $"Desert Bastion MesaWall tick {t} leg {i}: wall snap teleport {jump:F3}m >= 1.60m");
prevSoles[i] = ws.FootSole[i];
}
}
_output.WriteLine($"Desert Bastion MesaWall: maxJump={maxJump:F3}m, maxPOver={maxPOver:F3}m, maxSwOver={maxSwOver:F3}m");
}
// 2. Sion Paladin walking alongside tall building wall
using (var sion = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion, slot0Human: true))
{
for (int i = 1; i < sion.State.Contenders.Count; i++)
{
sion.SetContenderPose(i, 900f + i * 16f, 900f);
}
var bldg = sion.State.SionMap!.Buildings.First(b => (b.RoofY - b.GroundY) >= 6f && MathF.Abs(b.CenterX) < 500f && MathF.Abs(b.CenterZ) < 500f);
float startX = bldg.CenterX - bldg.HalfX - 4.5f;
float startZ = bldg.CenterZ - bldg.HalfZ - 12f;
sion.SetContenderPose(0, startX, startZ, 0f);
sion.State.SpawnChassisDrop(startX, startZ, Catalog.Paladin);
Assert.True(sion.TrySwapNearbyChassis(0));
sion.SetContenderPose(0, startX, startZ, 0f);
var player = sion.State.Contenders[0];
var body = sion.GetContenderBody(player.Id)!.Value;
var ws = sion.GetWalkerState(true, player.Id)!;
var view = sion.World.View;
int lane = body.Lane;
Vector3[] prevSoles = new Vector3[ws.Geom.LegCount];
for (int i = 0; i < ws.Geom.LegCount; i++) prevSoles[i] = ws.FootSole[i];
float maxJump = 0f;
for (int t = 0; t < 150; t++)
{
sion.SetHumanInput(0, new PlayerInput(0.8f, 0.08f, startX + 2f, bldg.CenterZ + bldg.HalfZ + 20f, false, false, false));
sion.Step();
var comPos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
var qYaw = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
var qTotal = Quaternion.Normalize(qYaw * Quaternion.CreateFromYawPitchRoll(0f, ws.LeanPitch, ws.LeanRoll));
Vector3 pelvisW = Vector3.Transform(ws.PelvisOffset, qYaw);
for (int i = 0; i < ws.Geom.LegCount; i++)
{
float jump = Vector3.Distance(ws.FootSole[i], prevSoles[i]);
if (jump > maxJump) maxJump = jump;
Vector3 hipW = comPos + pelvisW + Vector3.Transform(ws.Geom.Legs[i].HipInCom * ws.GeomScale, qTotal);
Vector3 ankW = ws.FootSole[i] + ws.FootNormal[i] * (ws.Geom.Legs[i].AnkleH * ws.GeomScale);
float dist3D = Vector3.Distance(ankW, hipW);
float maxR = ws.Geom.Legs[i].MaxLegReach * ws.GeomScale;
float limit = ws.Planted[i] ? maxR + 0.05f : maxR * 1.02f + 0.03f;
Assert.True(dist3D <= limit, $"Sion Paladin wall tick {t} leg {i}: reach {dist3D:F3} > {limit:F3}");
Assert.True(jump < 1.60f, $"Sion Paladin wall tick {t} leg {i}: wall snap teleport {jump:F3}m >= 1.60m");
prevSoles[i] = ws.FootSole[i];
}
}
_output.WriteLine($"Sion Paladin wall: maxJump={maxJump:F3}m");
}
}
[Fact]
public void SoulPass3_ManticoreArachnid_IkFkParity_ZeroKneeSaturation()
{
static Vector3 ComputeArachnidFkAnkleLocal(WalkerLegSpec leg, float scale, in WalkerLegAngles ang)
{
Vector3 r0 = leg.LegRight0;
Vector3 f0 = leg.LegFwd0;
float coxaYaw = ang.HipRoll;
Vector3 legOut = f0 * MathF.Cos(coxaYaw) + r0 * MathF.Sin(coxaYaw);
Vector3 s1Dir = legOut * MathF.Cos(ang.HipPitch) + Vector3.UnitY * MathF.Sin(ang.HipPitch);
float s2Elev = ang.HipPitch - ang.KneeFlex;
Vector3 s2Dir = legOut * MathF.Cos(s2Elev) + Vector3.UnitY * MathF.Sin(s2Elev);
return s1Dir * (leg.L1 * scale) + s2Dir * (leg.L2 * scale);
}
// 1. Direct IK -> FK parity across full 360-degree coxa sweep including dz < 0 behind LegFwd0
var mGeom = WalkerGeometrySpec.Manticore;
for (int legIdx = 0; legIdx < mGeom.LegCount; legIdx++)
{
var leg = mGeom.Legs[legIdx];
for (int deg = -165; deg <= 165; deg += 15)
{
float rad = deg * (MathF.PI / 180f);
float r = 1.45f;
Vector3 deltaLocal = (leg.LegFwd0 * MathF.Cos(rad) + leg.LegRight0 * MathF.Sin(rad)) * r + new Vector3(0f, -0.45f, 0f);
WalkerLegAngles ang = WalkerLocomotion.SolveLegTargetAngles(
mGeom, 1f, legIdx, Vector3.Zero, Quaternion.Identity, deltaLocal, Vector3.UnitY, 0f);
Vector3 fk = ComputeArachnidFkAnkleLocal(leg, 1f, ang);
float err = Vector3.Distance(fk, deltaLocal);
Assert.True(err < 0.01f, $"Manticore leg {legIdx} angle {deg}deg: IK/FK mismatch {err:F4}m (coxaYaw={ang.HipRoll:F3})");
Assert.True(ang.KneeFlex < 2.95f, $"Manticore leg {legIdx} angle {deg}deg: knee saturated {ang.KneeFlex:F3}");
}
}
// 2. Live flat Desert walk + sharp turns: verify actuator FK parity & zero knee saturation
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert, slot0Human: true);
for (int i = 1; i < session.State.Contenders.Count; i++)
{
session.SetContenderPose(i, 900f + i * 16f, 900f);
}
session.SetContenderPose(0, 0f, 0f, 0f);
session.State.SpawnChassisDrop(0f, 0f, Catalog.Manticore);
Assert.True(session.TrySwapNearbyChassis(0));
session.SetContenderPose(0, 0f, 0f, 0f);
var player = session.State.Contenders[0];
var body = session.GetContenderBody(player.Id)!.Value;
var ws = session.GetWalkerState(true, player.Id)!;
var view = session.World.View;
int lane = body.Lane;
float maxFkErr = 0f;
float maxTargetFkErr = 0f;
float maxFlatTargetFkErr = 0f;
float maxAngularFkErr = 0f;
float maxKneeFlex = 0f;
float maxFlatKneeFlex = 0f;
for (int t = 0; t < 180; t++)
{
float steer = t < 60 ? 0f : (t < 120 ? 0.45f : -0.45f);
float aimYaw = player.Yaw + steer * 0.45f;
session.SetHumanInput(0, new PlayerInput(
1.0f, steer,
player.X + 40f * MathF.Sin(aimYaw),
player.Z + 40f * MathF.Cos(aimYaw),
false, false, false));
session.Step();
var comPos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
var qYaw = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
var qTotal = Quaternion.Normalize(qYaw * Quaternion.CreateFromYawPitchRoll(0f, ws.LeanPitch, ws.LeanRoll));
Quaternion qInv = Quaternion.Conjugate(qTotal);
Vector3 pelvisW = Vector3.Transform(ws.PelvisOffset, qYaw);
for (int i = 0; i < ws.Geom.LegCount; i++)
{
var leg = ws.Geom.Legs[i];
Vector3 hipW = comPos + pelvisW + Vector3.Transform(leg.HipInCom * ws.GeomScale, qTotal);
Vector3 ankW = ws.FootSole[i] + ws.FootNormal[i] * (leg.AnkleH * ws.GeomScale);
Vector3 targetLocal = Vector3.Transform(ankW - hipW, qInv);
var tgtAng = WalkerLocomotion.SolveLegTargetAngles(
ws.Geom, ws.GeomScale, i, hipW, qTotal, ankW, ws.FootNormal[i], 0f,
ws.Actuators[i].Theta.HipRoll, hasPrevCoxaYaw: true);
Vector3 tgtFk = ComputeArachnidFkAnkleLocal(leg, ws.GeomScale, tgtAng);
float tErr = Vector3.Distance(tgtFk, targetLocal);
float tLen = targetLocal.Length();
float clampedLen = Math.Clamp(tLen, leg.MinLegReach * ws.GeomScale, leg.MaxLegReach * ws.GeomScale);
Vector3 reachableTarget = tLen > 1e-5f ? targetLocal * (clampedLen / tLen) : targetLocal;
float angErr = Vector3.Distance(tgtFk, reachableTarget);
maxAngularFkErr = MathF.Max(maxAngularFkErr, angErr);
maxTargetFkErr = MathF.Max(maxTargetFkErr, tErr);
if (t < 60) maxFlatTargetFkErr = MathF.Max(maxFlatTargetFkErr, tErr);
var actAng = ws.Actuators[i].Theta;
Vector3 actFk = ComputeArachnidFkAnkleLocal(leg, ws.GeomScale, actAng);
float aErr = Vector3.Distance(actFk, targetLocal);
maxFkErr = MathF.Max(maxFkErr, aErr);
maxKneeFlex = MathF.Max(maxKneeFlex, actAng.KneeFlex);
if (t < 60) maxFlatKneeFlex = MathF.Max(maxFlatKneeFlex, actAng.KneeFlex);
}
}
_output.WriteLine($"Manticore Desert walk/turn: flatMaxTargetFkErr={maxFlatTargetFkErr:F4}m, maxTargetFkErr={maxTargetFkErr:F4}m, maxAngularFkErr={maxAngularFkErr:F4}m, maxActFkErr={maxFkErr:F4}m, flatMaxKnee={maxFlatKneeFlex:F3}rad, maxKneeFlex={maxKneeFlex:F3}rad");
Assert.True(maxAngularFkErr < 0.01f, $"Manticore IK/FK angular mismatch {maxAngularFkErr:F4}m >= 0.01m");
Assert.True(maxFlatTargetFkErr < 0.10f, $"Manticore flat Desert IK/FK mismatch {maxFlatTargetFkErr:F4}m >= 0.10m");
Assert.True(maxTargetFkErr < 0.10f, $"Manticore IK/FK target mismatch {maxTargetFkErr:F4}m >= 0.10m");
Assert.True(maxFlatKneeFlex < 2.90f, $"Manticore flat knee near saturation {maxFlatKneeFlex:F3} rad");
Assert.True(maxKneeFlex < 3.05f, $"Manticore knee saturated at {maxKneeFlex:F3} rad");
}
}
}