cut11b(ymir): fix uphill stall, airborne pelvis jump, and liftoff reach guard

This commit is contained in:
Meta Vens 2026-12-06 04:15:29 +01:00
commit ff5eaccf2e

View file

@ -1098,9 +1098,12 @@ namespace RustToDust.Ymir
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);
bool nearTerrainSurface = pos.Y <= curCenterY + 0.65f;
float maxSlopeVy = (ws.WasGrounded || ws.Grounded)
? Math.Clamp(rawSlopeVy + 0.45f, 0.25f, 9.45f)
: 0.25f;
: (nearTerrainSurface ? Math.Clamp(rawSlopeVy + 2.50f, 3.00f, 9.45f) : 0.25f);
if (vel.Y > maxSlopeVy)
{
vel.Y = maxSlopeVy;
@ -1255,9 +1258,10 @@ namespace RustToDust.Ymir
{
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;
bool nearTerrainSurface = pos.Y <= gTerrCenterY + 0.65f;
float maxSlopeVy = (ws.Grounded || ws.WasGrounded)
? Math.Clamp(rawSlopeVy + 0.45f, 0.25f, 9.45f)
: 0.25f;
: (nearTerrainSurface ? Math.Clamp(rawSlopeVy + 2.50f, 3.00f, 9.45f) : 0.25f);
if (vel.Y > maxSlopeVy)
{
vel.Y = maxSlopeVy;
@ -1431,7 +1435,7 @@ namespace RustToDust.Ymir
bodyDelta = Vector3.Zero;
}
float airClearance = 0.02f * scale;
Vector3 airPelvisW = Vector3.Transform(new Vector3(0f, 0.10f * scale, 0f), qYaw);
Vector3 airPelvisW = Vector3.Transform(ws.PelvisOffset, qYaw);
for (int i = 0; i < n; i++)
{
ws.Planted[i] = false;
@ -1457,7 +1461,16 @@ namespace RustToDust.Ymir
? carriedFoot + diff * (maxLocalRetract / diffLen)
: targetAirSole;
ProjectSoleAboveGroundWithinReach(hipAirW, ankleH, maxAirReach, terrain, world, comPos.Y + 0.8f, airClearance, ref nextSole, out Vector3 clampedAirN);
ProjectSoleAboveGroundWithinReach(hipAirW, 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();
float hardAirReach = maxAirReach * 1.055f;
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);
}
Vector3 nextNorm = clampedAirN;
ws.FootSole[i] = nextSole;
@ -2188,7 +2201,12 @@ namespace RustToDust.Ymir
float maxLiftoffMove = 0.31f * MathF.Max(1f, scale);
if (liftLen > maxLiftoffMove && liftLen > 1e-5f)
{
ws.FootSole[i] = startS + liftDelta * (maxLiftoffMove / liftLen);
Vector3 cappedLift = startS + liftDelta * (maxLiftoffMove / liftLen);
Vector3 liftAnk = cappedLift + ws.FootNormal[i] * ankleH;
if ((liftAnk - hipTotalW).Length() <= maxReach * 1.06f)
{
ws.FootSole[i] = cappedLift;
}
}
}
}