fix(ymir): fix InitializePose steep-slope bottomClearance, Reground slope range, and swing sphere clamp
This commit is contained in:
parent
889ec9f1f8
commit
25a8a1b652
1 changed files with 34 additions and 10 deletions
|
|
@ -156,7 +156,7 @@ namespace RustToDust.Ymir
|
|||
float rideH = Geom.ModelRideHeight * GeomScale;
|
||||
var centerHit = WalkerLocomotion.SampleGroundAt(terrain, world, comPos.X, comPos.Z, comPos.Y + 0.5f, 0.25f);
|
||||
float bottomClearance = (comPos.Y - rideH) - centerHit.SurfaceY;
|
||||
Grounded = centerHit.Hit && centerHit.Normal.Y >= MaxCliffGuardNormalY && bottomClearance <= 0.18f;
|
||||
Grounded = centerHit.Hit && centerHit.Normal.Y >= MaxCliffGuardNormalY && bottomClearance <= 0.28f;
|
||||
WasGrounded = Grounded;
|
||||
IsAirborne = !Grounded;
|
||||
WasAirborne = IsAirborne;
|
||||
|
|
@ -1081,6 +1081,7 @@ namespace RustToDust.Ymir
|
|||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
const float castLift = 0.25f;
|
||||
|
|
@ -1104,7 +1105,7 @@ namespace RustToDust.Ymir
|
|||
bool hasStatic = downHit.Hit &&
|
||||
!IsDesertFloorSlab(terrain, downHit.StableId) &&
|
||||
(downHit.Normal.Y >= WalkerState.MaxWalkableNormalY ||
|
||||
(downHit.StableId == ArenaSession.GroundStableId && terrN.Y >= WalkerState.MaxCliffGuardNormalY));
|
||||
(downHit.StableId == ArenaSession.GroundStableId && terrN.Y >= groundMinNy));
|
||||
float staticCenterY = hasStatic
|
||||
? castStart.Y - castSpan * downHit.Fraction + 0.005f
|
||||
: float.NegativeInfinity;
|
||||
|
|
@ -1118,7 +1119,7 @@ namespace RustToDust.Ymir
|
|||
{
|
||||
targetY = staticCenterY;
|
||||
}
|
||||
else if (terrN.Y >= WalkerState.MaxWalkableNormalY)
|
||||
else if (terrN.Y >= groundMinNy)
|
||||
{
|
||||
targetY = terrCenterY;
|
||||
}
|
||||
|
|
@ -1187,7 +1188,6 @@ namespace RustToDust.Ymir
|
|||
: Vector3.UnitY;
|
||||
|
||||
float gTerrCenterY = gTerrY + halfLength + radius * Math.Clamp(1f / MathF.Max(0.45f, gTerrN.Y), 1f, 1.25f);
|
||||
float groundMinNy = ws.WasGrounded ? 0.642788f : WalkerState.MaxCliffGuardNormalY; // keep grounded across brief 45-50 deg dune ripples while still gating cliffs
|
||||
bool terrGround = !terrain.IsHeightmapMode &&
|
||||
gTerrN.Y >= groundMinNy &&
|
||||
pos.Y <= gTerrCenterY + 0.18f;
|
||||
|
|
@ -1885,19 +1885,20 @@ namespace RustToDust.Ymir
|
|||
|
||||
Vector3 pelvisWorldShift = Vector3.Transform(ws.PelvisOffset, qYaw);
|
||||
|
||||
// Keep all soles locked inside 0.995 * MaxLegReach of visual hip (post-pelvis & post-lean)
|
||||
// Keep planted soles grounded inside 0.995 * MaxLegReach, and clamp swinging/airborne soles on 3D reach sphere
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
Vector3 hipTotalW = comPos + pelvisWorldShift + Vector3.Transform(geom.Legs[i].HipInCom * scale, qTotal);
|
||||
float ankleH = geom.Legs[i].AnkleH * scale;
|
||||
float maxReach = geom.Legs[i].MaxLegReach * scale * 0.995f;
|
||||
Vector3 oldSole = ws.FootSole[i];
|
||||
Vector3 clampedSole = oldSole;
|
||||
if (ClampSoleToReach(hipTotalW, geom.Legs[i].AnkleH * scale, maxReach, comPos, terrain, world, comPos.Y + 0.8f, ref clampedSole, out Vector3 clampedN))
|
||||
if (ws.Grounded && ws.Planted[i])
|
||||
{
|
||||
ws.FootSole[i] = clampedSole;
|
||||
ws.FootNormal[i] = clampedN;
|
||||
if (ws.Grounded && ws.Planted[i])
|
||||
Vector3 clampedSole = oldSole;
|
||||
if (ClampSoleToReach(hipTotalW, ankleH, maxReach, comPos, terrain, world, comPos.Y + 0.8f, ref clampedSole, out Vector3 clampedN))
|
||||
{
|
||||
ws.FootSole[i] = clampedSole;
|
||||
ws.FootNormal[i] = clampedN;
|
||||
float drag = MathF.Sqrt((clampedSole.X - oldSole.X) * (clampedSole.X - oldSole.X) +
|
||||
(clampedSole.Z - oldSole.Z) * (clampedSole.Z - oldSole.Z));
|
||||
if (drag > ws.MaxFootSlipM)
|
||||
|
|
@ -1906,6 +1907,29 @@ namespace RustToDust.Ymir
|
|||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector3 ankle = oldSole + ws.FootNormal[i] * ankleH;
|
||||
Vector3 delta = ankle - hipTotalW;
|
||||
float dist = delta.Length();
|
||||
if (dist > maxReach && dist > 1e-5f)
|
||||
{
|
||||
Vector3 clampedAnkle = hipTotalW + delta * (maxReach / dist);
|
||||
Vector3 clampedSole = clampedAnkle - ws.FootNormal[i] * ankleH;
|
||||
var under = SampleGroundAt(terrain, world, clampedSole.X, clampedSole.Z, comPos.Y + 0.8f);
|
||||
if (clampedSole.Y < under.SurfaceY)
|
||||
{
|
||||
clampedSole.Y = under.SurfaceY;
|
||||
Vector3 cd = (clampedSole + under.Normal * ankleH) - hipTotalW;
|
||||
float cdLen = cd.Length();
|
||||
if (cdLen > maxReach && cdLen > 1e-5f)
|
||||
{
|
||||
clampedSole = (hipTotalW + cd * (maxReach / cdLen)) - under.Normal * ankleH;
|
||||
}
|
||||
}
|
||||
ws.FootSole[i] = clampedSole;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int activePlantedCount = 0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue