cut11b(ymir): handle heightmap concave slopes/StartedSolid ground and short-leg sprint cadence
This commit is contained in:
parent
ff5eaccf2e
commit
0c7c31e25b
1 changed files with 52 additions and 14 deletions
|
|
@ -799,6 +799,24 @@ namespace RustToDust.Ymir
|
|||
if (ws.Grounded && !airborneImpulse && ws.GroundNormal.Y >= WalkerState.MaxCliffGuardNormalY)
|
||||
{
|
||||
float slopeVy = -(vHoriz.X * ws.GroundNormal.X + vHoriz.Z * ws.GroundNormal.Z) / ws.GroundNormal.Y;
|
||||
if (!blockedBySustainedCliff && hSpeed > 0.5f)
|
||||
{
|
||||
float probeDist = MathF.Min(radius * 0.70f, 1.8f);
|
||||
Vector3 moveDir = vHoriz / hSpeed;
|
||||
float terrHere = terrain.SampleHeight(pos.X, pos.Z);
|
||||
float ax = pos.X + moveDir.X * probeDist;
|
||||
float az = pos.Z + moveDir.Z * probeDist;
|
||||
float terrAhead = terrain.SampleHeight(ax, az);
|
||||
if (terrAhead > terrHere)
|
||||
{
|
||||
Vector3 aheadN = WalkerState.SampleTerrainNormal(terrain, ax, az);
|
||||
if (aheadN.Y >= WalkerState.MaxCliffGuardNormalY)
|
||||
{
|
||||
float aheadSlopeVy = ((terrAhead - terrHere) / probeDist) * hSpeed;
|
||||
slopeVy = MathF.Max(slopeVy, MathF.Min(aheadSlopeVy, 14f));
|
||||
}
|
||||
}
|
||||
}
|
||||
targetVy = Math.Clamp(slopeVy, -18f, blockedBySustainedCliff ? 0f : 16f);
|
||||
view.ForceX[lane] = 0f;
|
||||
view.ForceY[lane] = mass * WalkerState.ArenaGravity;
|
||||
|
|
@ -1100,10 +1118,9 @@ namespace RustToDust.Ymir
|
|||
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)
|
||||
: (nearTerrainSurface ? Math.Clamp(rawSlopeVy + 2.50f, 3.00f, 9.45f) : 0.25f);
|
||||
: 0.25f;
|
||||
if (vel.Y > maxSlopeVy)
|
||||
{
|
||||
vel.Y = maxSlopeVy;
|
||||
|
|
@ -1202,13 +1219,29 @@ namespace RustToDust.Ymir
|
|||
// 4. CategorizeGround & Landing Impact Detection
|
||||
const float catLift = 0.22f;
|
||||
float catSpan = catLift + 0.18f;
|
||||
float catR = MathF.Max(0.25f, radius - 0.01f);
|
||||
var catHit = world.CastCapsuleClosest(
|
||||
(pos.X, pos.Y + catLift, pos.Z),
|
||||
MathF.Max(0.25f, radius - 0.01f),
|
||||
catR,
|
||||
halfLength,
|
||||
(0f, -catSpan, 0f),
|
||||
ignoreLane: lane,
|
||||
Box3DSoaQueryMask.Static);
|
||||
if (catHit.StartedSolid && !catHit.Hit)
|
||||
{
|
||||
const float highLift = 0.90f;
|
||||
var retryHit = world.CastCapsuleClosest(
|
||||
(pos.X, pos.Y + highLift, pos.Z),
|
||||
catR,
|
||||
halfLength,
|
||||
(0f, -(highLift + 0.18f), 0f),
|
||||
ignoreLane: lane,
|
||||
Box3DSoaQueryMask.Static);
|
||||
if (retryHit.Hit || !retryHit.StartedSolid)
|
||||
{
|
||||
catHit = retryHit;
|
||||
}
|
||||
}
|
||||
|
||||
float gTerrY = terrain.SampleHeight(pos.X, pos.Z);
|
||||
Vector3 gTerrN = WalkerState.SampleTerrainNormal(terrain, pos.X, pos.Z);
|
||||
|
|
@ -1224,9 +1257,9 @@ namespace RustToDust.Ymir
|
|||
: Vector3.UnitY;
|
||||
|
||||
float gTerrCenterY = gTerrY + halfLength + radius * Math.Clamp(1f / MathF.Max(0.45f, gTerrN.Y), 1f, 1.25f);
|
||||
bool terrGround = !terrain.IsHeightmapMode &&
|
||||
bool terrGround = (!terrain.IsHeightmapMode || (catHit.StartedSolid && !catHit.Hit && pos.Y >= gTerrY)) &&
|
||||
gTerrN.Y >= groundMinNy &&
|
||||
pos.Y <= gTerrCenterY + 0.18f;
|
||||
pos.Y <= gTerrCenterY + 0.22f;
|
||||
if (staticIsHeightfield && gTerrY < pos.Y - physHalfH - 0.05f)
|
||||
{
|
||||
staticGround = false;
|
||||
|
|
@ -1258,10 +1291,9 @@ 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)
|
||||
: (nearTerrainSurface ? Math.Clamp(rawSlopeVy + 2.50f, 3.00f, 9.45f) : 0.25f);
|
||||
: 0.25f;
|
||||
if (vel.Y > maxSlopeVy)
|
||||
{
|
||||
vel.Y = maxSlopeVy;
|
||||
|
|
@ -1502,12 +1534,13 @@ namespace RustToDust.Ymir
|
|||
float baseDur = Math.Clamp(0.48f * MathF.Sqrt(hScale), 0.24f, 0.58f);
|
||||
float speedDurRatio = Math.Clamp(30f / MathF.Max(8f, grid.Spec.MaxSpeed), 0.65f, 1.0f);
|
||||
float minDur = Math.Clamp(0.245f * MathF.Pow(hScale, 0.55f) * speedDurRatio, 0.085f, 0.32f);
|
||||
float effectiveDur = baseDur * (1f - 0.28f * speedFrac);
|
||||
float effectiveDur = MathF.Max(minDur, baseDur * (1f - 0.28f * speedFrac));
|
||||
float crouchFrac = n == 2 ? Math.Clamp(horizSpeed / MathF.Max(5f, grid.Spec.MaxSpeed * 0.35f), 0f, 1f) : speedFrac;
|
||||
float crouchCoeff = 0.055f + 0.072f * straightness;
|
||||
float crouchBias = n == 2 ? crouchCoeff * geom.ModelHalfHeight * scale * crouchFrac : 0f;
|
||||
|
||||
// Bound step duration so stance travel stays inside physical horizontal reach at sprint speed
|
||||
float durFloor = minDur;
|
||||
if (horizSpeed > 1.0f)
|
||||
{
|
||||
for (int i = 0; i < n; i++)
|
||||
|
|
@ -1518,22 +1551,27 @@ namespace RustToDust.Ymir
|
|||
float nominalDy = MathF.Max(0.25f * scale, MathF.Min(actualDy, rideHeight - crouchBias + geom.Legs[i].HipInCom.Y * scale - geom.Legs[i].AnkleH * scale));
|
||||
float availReach = geom.Legs[i].MaxLegReach * scale;
|
||||
float maxHorizStride = MathF.Sqrt(MathF.Max(0.25f * scale * scale, availReach * availReach - nominalDy * nominalDy));
|
||||
effectiveDur = MathF.Min(effectiveDur, (0.92f * maxHorizStride) / horizSpeed);
|
||||
float reachDur = (0.85f * maxHorizStride) / horizSpeed;
|
||||
if (reachDur < durFloor)
|
||||
{
|
||||
durFloor = MathF.Max(0.062f, reachDur);
|
||||
}
|
||||
effectiveDur = MathF.Min(effectiveDur, reachDur);
|
||||
}
|
||||
}
|
||||
effectiveDur = Math.Clamp(effectiveDur, minDur, 0.54f);
|
||||
effectiveDur = Math.Clamp(effectiveDur, durFloor, 0.54f);
|
||||
float overlap = MathF.Max(effOverlap, MathF.Min(0.32f, (dt / MathF.Max(0.04f, effectiveDur)) * 1.02f));
|
||||
|
||||
ws.SwingTime += dt;
|
||||
ws.SwingPhase += dt / MathF.Max(minDur, effectiveDur);
|
||||
ws.SwingPhase += dt / MathF.Max(durFloor, effectiveDur);
|
||||
|
||||
// Early step-completion break if a planted leg reaches > effectiveBreakFrac * MaxLegReach
|
||||
bool earlyBreak = false;
|
||||
float minBreakTime = n == 4
|
||||
? (ws.FirstStepFromIdle
|
||||
? Math.Clamp(minDur * 0.41f, 0.075f, 0.15f)
|
||||
: Math.Clamp(minDur * 0.69f, 0.205f, 0.22f))
|
||||
: Math.Clamp(minDur * (ws.FirstStepFromIdle ? 0.68f : 0.90f), 0.075f, 0.22f);
|
||||
? Math.Clamp(effectiveDur * 0.41f, 0.060f, 0.15f)
|
||||
: Math.Clamp(effectiveDur * 0.69f, 0.140f, 0.22f))
|
||||
: Math.Clamp(effectiveDur * (ws.FirstStepFromIdle ? 0.65f : 0.78f), 0.045f, 0.22f);
|
||||
if (ws.SwingTime >= minBreakTime && ws.SwingPhase > overlap + 0.15f)
|
||||
{
|
||||
Vector3 curPelvisShift = Vector3.Transform(ws.PelvisOffset, qYaw);
|
||||
|
|
|
|||
Loading…
Reference in a new issue