cut11b: damp feedforward, tighten reverse-knee clearance, and bound 1-tick foot deltas cleanly
This commit is contained in:
parent
9b7c83e471
commit
f5a061fa5a
1 changed files with 38 additions and 31 deletions
|
|
@ -799,25 +799,7 @@ namespace RustToDust.Ymir
|
||||||
if (ws.Grounded && !airborneImpulse && ws.GroundNormal.Y >= WalkerState.MaxCliffGuardNormalY)
|
if (ws.Grounded && !airborneImpulse && ws.GroundNormal.Y >= WalkerState.MaxCliffGuardNormalY)
|
||||||
{
|
{
|
||||||
float slopeVy = -(vHoriz.X * ws.GroundNormal.X + vHoriz.Z * ws.GroundNormal.Z) / ws.GroundNormal.Y;
|
float slopeVy = -(vHoriz.X * ws.GroundNormal.X + vHoriz.Z * ws.GroundNormal.Z) / ws.GroundNormal.Y;
|
||||||
const float maxClimbVy = 9.0f;
|
targetVy = Math.Clamp(slopeVy, -18f, blockedBySustainedCliff ? 0f : 16f);
|
||||||
if (slopeVy > maxClimbVy && !blockedBySustainedCliff)
|
|
||||||
{
|
|
||||||
float climbScale = maxClimbVy / slopeVy;
|
|
||||||
Vector3 downXZ = new(ws.GroundNormal.X, 0f, ws.GroundNormal.Z);
|
|
||||||
float downLen = downXZ.Length();
|
|
||||||
if (downLen > 1e-4f)
|
|
||||||
{
|
|
||||||
downXZ /= downLen;
|
|
||||||
float upComp = -Vector3.Dot(vHoriz, downXZ);
|
|
||||||
if (upComp > 0f)
|
|
||||||
{
|
|
||||||
vHoriz += downXZ * (upComp * (1f - climbScale));
|
|
||||||
hSpeed = vHoriz.Length();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
slopeVy = maxClimbVy;
|
|
||||||
}
|
|
||||||
targetVy = Math.Clamp(slopeVy, -18f, blockedBySustainedCliff ? 0f : maxClimbVy);
|
|
||||||
view.ForceX[lane] = 0f;
|
view.ForceX[lane] = 0f;
|
||||||
view.ForceY[lane] = mass * WalkerState.ArenaGravity;
|
view.ForceY[lane] = mass * WalkerState.ArenaGravity;
|
||||||
view.ForceZ[lane] = 0f;
|
view.ForceZ[lane] = 0f;
|
||||||
|
|
@ -1328,6 +1310,7 @@ namespace RustToDust.Ymir
|
||||||
int n = geom.LegCount;
|
int n = geom.LegCount;
|
||||||
float rideHeight = geom.ModelRideHeight * scale;
|
float rideHeight = geom.ModelRideHeight * scale;
|
||||||
bool preTickPlanted0 = ws.Planted[0], preTickPlanted1 = ws.Planted[1], preTickPlanted2 = ws.Planted[2], preTickPlanted3 = ws.Planted[3];
|
bool preTickPlanted0 = ws.Planted[0], preTickPlanted1 = ws.Planted[1], preTickPlanted2 = ws.Planted[2], preTickPlanted3 = ws.Planted[3];
|
||||||
|
Vector3 startSole0 = ws.FootSole[0], startSole1 = ws.FootSole[1], startSole2 = ws.FootSole[2], startSole3 = ws.FootSole[3];
|
||||||
|
|
||||||
Span<float> legIntegrities = stackalloc float[4];
|
Span<float> legIntegrities = stackalloc float[4];
|
||||||
grid.GetLegIntegrities(legIntegrities);
|
grid.GetLegIntegrities(legIntegrities);
|
||||||
|
|
@ -1474,7 +1457,7 @@ namespace RustToDust.Ymir
|
||||||
Vector3 carriedFoot = ws.FootSole[i] + bodyDelta;
|
Vector3 carriedFoot = ws.FootSole[i] + bodyDelta;
|
||||||
Vector3 diff = targetAirSole - carriedFoot;
|
Vector3 diff = targetAirSole - carriedFoot;
|
||||||
float diffLen = diff.Length();
|
float diffLen = diff.Length();
|
||||||
float maxLocalRetract = Math.Clamp(MathF.Max(14f, horizSpeed * 1.6f) * dt, 0.25f * scale, 0.95f * scale);
|
float maxLocalRetract = Math.Clamp(MathF.Max(8f, horizSpeed * 1.1f) * dt, 0.25f * scale, 0.65f * scale);
|
||||||
Vector3 nextSole = diffLen > maxLocalRetract && diffLen > 1e-5f
|
Vector3 nextSole = diffLen > maxLocalRetract && diffLen > 1e-5f
|
||||||
? carriedFoot + diff * (maxLocalRetract / diffLen)
|
? carriedFoot + diff * (maxLocalRetract / diffLen)
|
||||||
: targetAirSole;
|
: targetAirSole;
|
||||||
|
|
@ -1598,7 +1581,7 @@ namespace RustToDust.Ymir
|
||||||
{
|
{
|
||||||
landedNorm = clampedN;
|
landedNorm = clampedN;
|
||||||
}
|
}
|
||||||
float maxLandJump = MathF.Min(1.48f * MathF.Max(1f, scale), MathF.Max(1.15f * scale, horizSpeed * dt * 2.15f));
|
float maxLandJump = 1.56f * MathF.Max(1f, scale);
|
||||||
Vector3 landDelta = landedSole - ws.FootSole[i];
|
Vector3 landDelta = landedSole - ws.FootSole[i];
|
||||||
float landDist = landDelta.Length();
|
float landDist = landDelta.Length();
|
||||||
bool landCapped = false;
|
bool landCapped = false;
|
||||||
|
|
@ -1817,7 +1800,7 @@ namespace RustToDust.Ymir
|
||||||
geom.Legs[i].LegFwd0.Z * (geom.Legs[i].RestFootXZ.Y - geom.Legs[i].HipInCom.Z)) * scale;
|
geom.Legs[i].LegFwd0.Z * (geom.Legs[i].RestFootXZ.Y - geom.Legs[i].HipInCom.Z)) * scale;
|
||||||
if (restFwd < -0.25f * scale)
|
if (restFwd < -0.25f * scale)
|
||||||
{
|
{
|
||||||
float maxAllowedFwd = restFwd * 0.58f;
|
float maxAllowedFwd = restFwd * 0.78f;
|
||||||
float curFwd = (tx - hipPredW.X) * f0W.X + (tz - hipPredW.Z) * f0W.Z;
|
float curFwd = (tx - hipPredW.X) * f0W.X + (tz - hipPredW.Z) * f0W.Z;
|
||||||
if (curFwd > maxAllowedFwd)
|
if (curFwd > maxAllowedFwd)
|
||||||
{
|
{
|
||||||
|
|
@ -1835,7 +1818,7 @@ namespace RustToDust.Ymir
|
||||||
Vector3 reachCenter = Vector3.Lerp(predCom, comPos, legUSwing);
|
Vector3 reachCenter = Vector3.Lerp(predCom, comPos, legUSwing);
|
||||||
float comSurfY = SampleGroundAt(terrain, world, comPos.X, comPos.Z, comPos.Y + 0.6f).SurfaceY;
|
float comSurfY = SampleGroundAt(terrain, world, comPos.X, comPos.Z, comPos.Y + 0.6f).SurfaceY;
|
||||||
var tgtHit = SampleGroundAt(terrain, world, tx, tz, comPos.Y + 0.8f);
|
var tgtHit = SampleGroundAt(terrain, world, tx, tz, comPos.Y + 0.8f);
|
||||||
if (tgtHit.SurfaceY > comSurfY + WalkerState.MaxStepUpM * 1.45f)
|
if (tgtHit.FromStaticBoxOrMesh && tgtHit.SurfaceY > comSurfY + WalkerState.MaxStepUpM * 1.45f)
|
||||||
{
|
{
|
||||||
float loT = 0f, hiT = 1f;
|
float loT = 0f, hiT = 1f;
|
||||||
for (int b = 0; b < 4; b++)
|
for (int b = 0; b < 4; b++)
|
||||||
|
|
@ -1877,7 +1860,7 @@ namespace RustToDust.Ymir
|
||||||
float arcScale = Math.Clamp(1.05f - 0.33f * (geom.MeanHipSpan / MathF.Max(0.5f, geom.ModelRideHeight)), 0.65f, 0.85f);
|
float arcScale = Math.Clamp(1.05f - 0.33f * (geom.MeanHipSpan / MathF.Max(0.5f, geom.ModelRideHeight)), 0.65f, 0.85f);
|
||||||
float arcLift = (geom.SwingArcHeight * scale * arcScale + 0.12f * stepDiff) * MathF.Pow(legEnv, 1.40f);
|
float arcLift = (geom.SwingArcHeight * scale * arcScale + 0.12f * stepDiff) * MathF.Pow(legEnv, 1.40f);
|
||||||
var underHit = SampleGroundAt(terrain, world, sx, sz, comPos.Y + 0.8f);
|
var underHit = SampleGroundAt(terrain, world, sx, sz, comPos.Y + 0.8f);
|
||||||
float maxSwingStep = MathF.Min(1.48f * MathF.Max(1f, scale), MathF.Max(0.95f * scale, horizSpeed * dt * 2.15f));
|
float maxSwingStep = MathF.Min(1.56f * MathF.Max(1f, scale), MathF.Max(1.30f * scale, horizSpeed * dt * 3.0f));
|
||||||
float clampedUnderY = MathF.Min(underHit.SurfaceY, ws.FootSole[i].Y + maxSwingStep * 0.90f);
|
float clampedUnderY = MathF.Min(underHit.SurfaceY, ws.FootSole[i].Y + maxSwingStep * 0.90f);
|
||||||
float minGround = clampedUnderY + 0.10f * scale * legEnv;
|
float minGround = clampedUnderY + 0.10f * scale * legEnv;
|
||||||
Vector3 desiredSole = new(sx, MathF.Max(syBase + arcLift, minGround), sz);
|
Vector3 desiredSole = new(sx, MathF.Max(syBase + arcLift, minGround), sz);
|
||||||
|
|
@ -2194,6 +2177,24 @@ namespace RustToDust.Ymir
|
||||||
ws.FootSole[i] = clampedSole;
|
ws.FootSole[i] = clampedSole;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ws.Grounded && !ws.WasAirborne)
|
||||||
|
{
|
||||||
|
Vector3 tickStartSole = i switch { 0 => startSole0, 1 => startSole1, 2 => startSole2, _ => startSole3 };
|
||||||
|
Vector3 tickDelta = ws.FootSole[i] - tickStartSole;
|
||||||
|
float tickDist = tickDelta.Length();
|
||||||
|
float maxTotalTickMove = 1.56f * MathF.Max(1f, scale);
|
||||||
|
if (tickDist > maxTotalTickMove && tickDist > 1e-5f)
|
||||||
|
{
|
||||||
|
Vector3 capped = tickStartSole + tickDelta * (maxTotalTickMove / tickDist);
|
||||||
|
var gCap = SampleGroundAt(terrain, world, capped.X, capped.Z, comPos.Y + 0.8f);
|
||||||
|
if (gCap.SurfaceY <= tickStartSole.Y + maxTotalTickMove * 0.90f && capped.Y < gCap.SurfaceY)
|
||||||
|
{
|
||||||
|
capped.Y = gCap.SurfaceY;
|
||||||
|
}
|
||||||
|
ws.FootSole[i] = capped;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int activePlantedCount = 0;
|
int activePlantedCount = 0;
|
||||||
|
|
@ -2204,8 +2205,8 @@ namespace RustToDust.Ymir
|
||||||
|
|
||||||
float subDt = dt * 0.25f;
|
float subDt = dt * 0.25f;
|
||||||
float limbI = MathF.Max(1f, mass * scale * scale * 0.025f);
|
float limbI = MathF.Max(1f, mass * scale * scale * 0.025f);
|
||||||
float kpBaseStance = geom.IsArachnidUp ? 5600f : 8400f;
|
float kpBaseStance = geom.IsArachnidUp ? 5600f : 8800f;
|
||||||
float kpBaseSwing = geom.IsArachnidUp ? 4400f : 6600f;
|
float kpBaseSwing = geom.IsArachnidUp ? 4400f : 6800f;
|
||||||
float kpStance = limbI * kpBaseStance;
|
float kpStance = limbI * kpBaseStance;
|
||||||
float kpSwing = limbI * kpBaseSwing;
|
float kpSwing = limbI * kpBaseSwing;
|
||||||
float kdStance = limbI * (2f * 0.85f * MathF.Sqrt(kpBaseStance));
|
float kdStance = limbI * (2f * 0.85f * MathF.Sqrt(kpBaseStance));
|
||||||
|
|
@ -2239,11 +2240,17 @@ namespace RustToDust.Ymir
|
||||||
ref var act = ref ws.Actuators[i];
|
ref var act = ref ws.Actuators[i];
|
||||||
WalkerLegAngles prevTgt = ws.HasPrevTarget ? ws.PrevTargetAngles[i] : target;
|
WalkerLegAngles prevTgt = ws.HasPrevTarget ? ws.PrevTargetAngles[i] : target;
|
||||||
float invDt = dt > 1e-5f ? 1f / dt : 0f;
|
float invDt = dt > 1e-5f ? 1f / dt : 0f;
|
||||||
float refHipPitch = Math.Clamp((target.HipPitch - prevTgt.HipPitch) * invDt, -14f, 14f);
|
float ffGain = (ws.HasPrevTarget && !geom.IsArachnidUp && !isTouchdownTick) ? 0.50f : 0f;
|
||||||
float refHipRoll = Math.Clamp((target.HipRoll - prevTgt.HipRoll) * invDt, -14f, 14f);
|
static float SmoothTargetOmega(float cur, float prev, float invDt, float gain)
|
||||||
float refKnee = Math.Clamp((target.KneeFlex - prevTgt.KneeFlex) * invDt, -16f, 16f);
|
{
|
||||||
float refHock = Math.Clamp((target.HockFlex - prevTgt.HockFlex) * invDt, -16f, 16f);
|
float d = cur - prev;
|
||||||
float refAnkle = Math.Clamp((target.AnklePitch - prevTgt.AnklePitch) * invDt, -14f, 14f);
|
return gain > 0f && MathF.Abs(d) < 0.22f ? Math.Clamp(d * invDt, -6f, 6f) * gain : 0f;
|
||||||
|
}
|
||||||
|
float refHipPitch = SmoothTargetOmega(target.HipPitch, prevTgt.HipPitch, invDt, ffGain);
|
||||||
|
float refHipRoll = SmoothTargetOmega(target.HipRoll, prevTgt.HipRoll, invDt, ffGain);
|
||||||
|
float refKnee = SmoothTargetOmega(target.KneeFlex, prevTgt.KneeFlex, invDt, ffGain);
|
||||||
|
float refHock = SmoothTargetOmega(target.HockFlex, prevTgt.HockFlex, invDt, ffGain);
|
||||||
|
float refAnkle = SmoothTargetOmega(target.AnklePitch, prevTgt.AnklePitch, invDt, ffGain);
|
||||||
for (int sub = 0; sub < 4; sub++)
|
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.HipPitch, ref act.Omega.HipPitch, target.HipPitch, refHipPitch, kp, kd, tauHipMax, limbI, 0f, subDt);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue