From 3964017458e6c1901f06d1fc713f2ec7445bacc5 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 6 Dec 2026 03:49:29 +0100 Subject: [PATCH] cut11b: fix Soul Pass #2 foot ground clamp, curb teleports, Sion launches, and Smoke clearances --- client/VehicleVisualInstance.cs | 3 +- src/RustToDust.Core/GridChassis.cs | 3 +- src/RustToDust.Core/WalkerGeometrySpec.cs | 48 ++- src/RustToDust.Ymir/WalkerLocomotion.cs | 358 +++++++++++++++---- tests/RustToDust.Tests/HybridBWalkerTests.cs | 123 +++++-- 5 files changed, 401 insertions(+), 134 deletions(-) diff --git a/client/VehicleVisualInstance.cs b/client/VehicleVisualInstance.cs index 5c01e3d..7fc4d9f 100644 --- a/client/VehicleVisualInstance.cs +++ b/client/VehicleVisualInstance.cs @@ -200,8 +200,7 @@ public sealed class VehicleVisualInstance bool isWalker = role != VehicleVisualRole.SalvageDrop && (pkg.Mobility == MobilityKind.Walker || pkg.Plane == GridPlane.Coronal || - string.Equals(pkg.Id, "manticore", StringComparison.OrdinalIgnoreCase) || - string.Equals(pkg.Id, "bastion", StringComparison.OrdinalIgnoreCase)); + WalkerGeometrySpec.TryGetForChassis(pkg.Id, out _)); float groundOffset = isWalker ? WalkerGeometrySpec.GetForChassis(pkg.Id).ModelRideHeight * effectiveScale : halfHeight; diff --git a/src/RustToDust.Core/GridChassis.cs b/src/RustToDust.Core/GridChassis.cs index 8979b54..029e6d6 100644 --- a/src/RustToDust.Core/GridChassis.cs +++ b/src/RustToDust.Core/GridChassis.cs @@ -127,8 +127,7 @@ namespace RustToDust.Core public bool IsWalker => Mobility == MobilityKind.Walker || Plane == GridPlane.Coronal || - string.Equals(Id, "manticore", StringComparison.OrdinalIgnoreCase) || - string.Equals(Id, "bastion", StringComparison.OrdinalIgnoreCase); + WalkerGeometrySpec.TryGetForChassis(Id, out _); public bool IsVtol => Mobility == MobilityKind.Vtol; diff --git a/src/RustToDust.Core/WalkerGeometrySpec.cs b/src/RustToDust.Core/WalkerGeometrySpec.cs index abff408..ab891e9 100644 --- a/src/RustToDust.Core/WalkerGeometrySpec.cs +++ b/src/RustToDust.Core/WalkerGeometrySpec.cs @@ -139,19 +139,43 @@ namespace RustToDust.Core public static readonly WalkerGeometrySpec Manticore = BuildManticore(); public static readonly WalkerGeometrySpec Bastion = BuildBastion(); - public static WalkerGeometrySpec GetForChassis(string chassisId) => - chassisId.ToLowerInvariant() switch + public static bool TryGetForChassis(string? chassisId, out WalkerGeometrySpec spec) + { + switch (chassisId?.ToLowerInvariant()) { - "breaker" => Breaker, - "paladin" => Paladin, - "raptor" => Raptor, - "exemplar_frame" => Raptor, - "spectre" => Spectre, - "kestrel" => Kestrel, - "manticore" => Manticore, - "bastion" => Bastion, - _ => Raptor - }; + case "breaker": + spec = Breaker; + return true; + case "paladin": + spec = Paladin; + return true; + case "raptor": + case "exemplar_frame": + spec = Raptor; + return true; + case "spectre": + spec = Spectre; + return true; + case "kestrel": + spec = Kestrel; + return true; + case "manticore": + spec = Manticore; + return true; + case "bastion": + spec = Bastion; + return true; + default: + spec = Raptor; + return false; + } + } + + public static WalkerGeometrySpec GetForChassis(string chassisId) + { + TryGetForChassis(chassisId, out var spec); + return spec; + } private static WalkerGeometrySpec BuildBreaker() { diff --git a/src/RustToDust.Ymir/WalkerLocomotion.cs b/src/RustToDust.Ymir/WalkerLocomotion.cs index bec35f7..7d8dd62 100644 --- a/src/RustToDust.Ymir/WalkerLocomotion.cs +++ b/src/RustToDust.Ymir/WalkerLocomotion.cs @@ -32,6 +32,7 @@ namespace RustToDust.Ymir public bool PostStepGrounded; public bool PendingExternalImpulse; public bool PreStepHadUpwardImpulse; + public bool InExternalBlastArc; public Vector3 PrevHorizVel; public float MaxFootSlipM; public Vector3 PelvisOffset; @@ -86,6 +87,7 @@ namespace RustToDust.Ymir public bool PostStepGrounded; public bool PendingExternalImpulse; public bool PreStepHadUpwardImpulse; + public bool InExternalBlastArc; public Vector3 PrevHorizVel; public float MaxFootSlipM; public Vector3 PelvisOffset; @@ -257,6 +259,7 @@ namespace RustToDust.Ymir CurrSnap = BuildSnapshot(comPos, qYaw, mass); PrevSnap = CurrSnap; + InExternalBlastArc = false; Initialized = true; } @@ -285,6 +288,7 @@ namespace RustToDust.Ymir PostStepGrounded = PostStepGrounded, PendingExternalImpulse = PendingExternalImpulse, PreStepHadUpwardImpulse = PreStepHadUpwardImpulse, + InExternalBlastArc = InExternalBlastArc, PrevHorizVel = PrevHorizVel, MaxFootSlipM = MaxFootSlipM, PelvisOffset = PelvisOffset, @@ -329,6 +333,7 @@ namespace RustToDust.Ymir PostStepGrounded = cp.PostStepGrounded; PendingExternalImpulse = cp.PendingExternalImpulse; PreStepHadUpwardImpulse = cp.PreStepHadUpwardImpulse; + InExternalBlastArc = cp.InExternalBlastArc; PrevHorizVel = cp.PrevHorizVel; MaxFootSlipM = cp.MaxFootSlipM; PelvisOffset = cp.PelvisOffset; @@ -386,6 +391,7 @@ namespace RustToDust.Ymir { PendingExternalImpulse = true; PreStepHadUpwardImpulse = true; + InExternalBlastArc = true; } bool aboveGround = (comPos.Y - rideH) > gCenter.SurfaceY + 0.18f; @@ -406,6 +412,7 @@ namespace RustToDust.Ymir IsAirborne = true; PendingExternalImpulse = hasUpwardBlast; PreStepHadUpwardImpulse = hasUpwardBlast; + InExternalBlastArc = hasUpwardBlast; } return; } @@ -670,6 +677,14 @@ namespace RustToDust.Ymir ws.WasGrounded = ws.Grounded; bool externalImpulse = ws.PendingExternalImpulse || (ws.PostStepGrounded && vel.Y > ws.PostStepVelY + 0.65f); ws.PreStepHadUpwardImpulse = externalImpulse; + if (externalImpulse) + { + ws.InExternalBlastArc = true; + } + else if (ws.Grounded) + { + ws.InExternalBlastArc = false; + } ws.PendingExternalImpulse = false; ws.PrevHorizVel = new Vector3(vel.X, 0f, vel.Z); ws.PrevVelY = vel.Y; @@ -774,13 +789,35 @@ 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; - targetVy = Math.Clamp(slopeVy, -18f, blockedBySustainedCliff ? 0f : 16f); + const float maxClimbVy = 9.0f; + 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.ForceY[lane] = mass * WalkerState.ArenaGravity; view.ForceZ[lane] = 0f; } else { + if (!airborneImpulse && !ws.InExternalBlastArc && targetVy > 0.25f) + { + targetVy = 0.25f; + } view.ForceX[lane] = 0f; view.ForceY[lane] = 0f; view.ForceZ[lane] = 0f; @@ -1063,11 +1100,11 @@ namespace RustToDust.Ymir ws.DidStepUp = false; } - // 1b. Suppress spurious Box3D curb/corner solver launch when grounded without external upward impulse - if (!ws.PreStepHadUpwardImpulse && ws.WasGrounded && vel.Y > 0.25f) + // 1b. Suppress spurious Box3D curb/corner solver launch when not on an explicit external blast + if (!ws.PreStepHadUpwardImpulse && !ws.InExternalBlastArc && vel.Y > 0.25f) { - float maxSlopeVy = ws.GroundNormal.Y >= WalkerState.MaxCliffGuardNormalY - ? MathF.Max(0f, -(vel.X * ws.GroundNormal.X + vel.Z * ws.GroundNormal.Z) / ws.GroundNormal.Y) + 0.25f + float maxSlopeVy = ws.WasGrounded && ws.GroundNormal.Y >= WalkerState.MaxCliffGuardNormalY + ? Math.Clamp(-(vel.X * ws.GroundNormal.X + vel.Z * ws.GroundNormal.Z) / ws.GroundNormal.Y + 0.25f, 0.25f, 9.25f) : 0.25f; if (vel.Y > maxSlopeVy) { @@ -1214,10 +1251,15 @@ namespace RustToDust.Ymir ws.GroundNormal = gTerrN; } - if (ws.Grounded && !ws.PreStepHadUpwardImpulse && vel.Y > 0.25f) + if (ws.Grounded && !ws.PreStepHadUpwardImpulse) { - float maxSlopeVy = ws.GroundNormal.Y >= WalkerState.MaxWalkableNormalY - ? MathF.Max(0f, -(vel.X * ws.GroundNormal.X + vel.Z * ws.GroundNormal.Z) / ws.GroundNormal.Y) + 0.25f + ws.InExternalBlastArc = false; + } + + if (!ws.PreStepHadUpwardImpulse && !ws.InExternalBlastArc && vel.Y > 0.25f) + { + float maxSlopeVy = ws.Grounded && ws.GroundNormal.Y >= WalkerState.MaxWalkableNormalY + ? Math.Clamp(-(vel.X * ws.GroundNormal.X + vel.Z * ws.GroundNormal.Z) / ws.GroundNormal.Y + 0.25f, 0.25f, 9.25f) : 0.25f; if (vel.Y > maxSlopeVy) { @@ -1416,21 +1458,8 @@ namespace RustToDust.Ymir ? carriedFoot + diff * (maxLocalRetract / diffLen) : targetAirSole; - var underHit = SampleGroundAt(terrain, world, nextSole.X, nextSole.Z, comPos.Y + 0.8f); - Vector3 nextNorm = underHit.Normal; - if (nextSole.Y < underHit.SurfaceY + airClearance) - { - nextSole.Y = underHit.SurfaceY + airClearance; - } - if (ClampSoleToReach(hipAirW, ankleH, maxAirReach, comPos, terrain, world, comPos.Y + 0.8f, ref nextSole, out Vector3 clampedAirN)) - { - nextNorm = clampedAirN; - var postHit = SampleGroundAt(terrain, world, nextSole.X, nextSole.Z, comPos.Y + 0.8f); - if (nextSole.Y < postHit.SurfaceY + airClearance) - { - nextSole.Y = postHit.SurfaceY + airClearance; - } - } + ProjectSoleAboveGroundWithinReach(hipAirW, ankleH, maxAirReach, terrain, world, comPos.Y + 0.8f, airClearance, ref nextSole, out Vector3 clampedAirN); + Vector3 nextNorm = clampedAirN; ws.FootSole[i] = nextSole; ws.FootNormal[i] = Vector3.Normalize(Vector3.Lerp(ws.FootNormal[i], nextNorm, Math.Clamp(dt * 8f, 0f, 1f))); @@ -1548,23 +1577,40 @@ namespace RustToDust.Ymir { landedNorm = clampedN; } - if (earlyBreak && (landedSole - ws.FootSole[i]).Length() > maxPlantStep * 1.25f) + float maxLandJump = MathF.Min(1.48f * MathF.Max(1f, scale), MathF.Max(1.15f * scale, horizSpeed * dt * 2.15f)); + Vector3 landDelta = landedSole - ws.FootSole[i]; + float landDist = landDelta.Length(); + bool landCapped = false; + if (landDist > maxLandJump && landDist > 1e-5f) { - var curGround = SampleGroundAt(terrain, world, ws.FootSole[i].X, ws.FootSole[i].Z, comPos.Y + 0.8f); - Vector3 fallbackSole = new(ws.FootSole[i].X, curGround.SurfaceY, ws.FootSole[i].Z); - Vector3 fallbackNorm = curGround.Normal; - if (ClampSoleToReach(plantHip, plantAnkleH, plantMaxReach, comPos, terrain, world, comPos.Y + 0.8f, ref fallbackSole, out Vector3 fbClampedN)) + landedSole = ws.FootSole[i] + landDelta * (maxLandJump / landDist); + var capHit = SampleGroundAt(terrain, world, landedSole.X, landedSole.Z, comPos.Y + 0.8f); + landedNorm = capHit.Normal; + if (landedSole.Y < capHit.SurfaceY) { - fallbackNorm = fbClampedN; - } - if ((fallbackSole - ws.FootSole[i]).Length() < (landedSole - ws.FootSole[i]).Length()) - { - landedSole = fallbackSole; - landedNorm = fallbackNorm; + if (capHit.SurfaceY <= ws.FootSole[i].Y + maxLandJump * 0.90f) + { + landedSole.Y = capHit.SurfaceY; + } + else + { + Vector3 toCom = new(comPos.X - ws.FootSole[i].X, 0f, comPos.Z - ws.FootSole[i].Z); + float toComLen = toCom.Length(); + landedSole = toComLen > 1e-4f + ? ws.FootSole[i] + toCom * MathF.Min(0.25f, (maxLandJump * 0.5f) / toComLen) + : ws.FootSole[i]; + var inHit = SampleGroundAt(terrain, world, landedSole.X, landedSole.Z, comPos.Y + 0.8f); + if (inHit.SurfaceY <= ws.FootSole[i].Y + maxLandJump * 0.90f) + { + landedSole.Y = MathF.Max(landedSole.Y, inHit.SurfaceY); + } + landedNorm = inHit.Normal; + } } + landCapped = true; } var groundCheck = SampleGroundAt(terrain, world, landedSole.X, landedSole.Z, comPos.Y + 0.8f); - bool touchesGround = landedSole.Y <= groundCheck.SurfaceY + 0.055f * scale; + bool touchesGround = !landCapped && landedSole.Y <= groundCheck.SurfaceY + 0.055f * scale; candTouchesGround[i] = touchesGround; if (earlyBreak && ws.SwingPhase < 1.0f && !touchesGround) { @@ -1737,11 +1783,60 @@ namespace RustToDust.Ymir } } + if (geom.Legs[i].KneeBendSign < 0f && geom.Legs[i].L1 > geom.Legs[i].L2 * 2.0f) + { + // Reverse-knee long-thigh rear legs fold downward if the foot steps underneath the hip; keep behind clearance margin + Vector3 f0W = Vector3.Transform(geom.Legs[i].LegFwd0, predYaw); + f0W.Y = 0f; + if (f0W.LengthSquared() > 1e-5f) + { + f0W = Vector3.Normalize(f0W); + Vector3 hipPredW = predCom + Vector3.Transform(geom.Legs[i].HipInCom * scale, predYaw); + float restFwd = (geom.Legs[i].LegFwd0.X * (geom.Legs[i].RestFootXZ.X - geom.Legs[i].HipInCom.X) + + geom.Legs[i].LegFwd0.Z * (geom.Legs[i].RestFootXZ.Y - geom.Legs[i].HipInCom.Z)) * scale; + if (restFwd < -0.25f * scale) + { + float maxAllowedFwd = restFwd * 0.58f; + float curFwd = (tx - hipPredW.X) * f0W.X + (tz - hipPredW.Z) * f0W.Z; + if (curFwd > maxAllowedFwd) + { + float pull = maxAllowedFwd - curFwd; + tx += f0W.X * pull; + tz += f0W.Z * pull; + } + } + } + } + Vector3 predHip = predCom + new Vector3(0f, -crouchBias, 0f) + Vector3.Transform(geom.Legs[i].HipInCom * scale, predYaw); Vector3 curHip = comPos + new Vector3(0f, -crouchBias, 0f) + Vector3.Transform(geom.Legs[i].HipInCom * scale, qYaw); Vector3 reachHip = Vector3.Lerp(predHip, curHip, legUSwing); Vector3 reachCenter = Vector3.Lerp(predCom, comPos, legUSwing); + 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); + if (tgtHit.SurfaceY > comSurfY + WalkerState.MaxStepUpM * 1.45f) + { + float loT = 0f, hiT = 1f; + for (int b = 0; b < 4; b++) + { + float midT = 0.5f * (loT + hiT); + float mx = comPos.X + (tx - comPos.X) * midT; + float mz = comPos.Z + (tz - comPos.Z) * midT; + var mh = SampleGroundAt(terrain, world, mx, mz, comPos.Y + 0.8f); + if (mh.SurfaceY <= comSurfY + WalkerState.MaxStepUpM * 1.45f) + { + loT = midT; + tgtHit = mh; + } + else + { + hiT = midT; + } + } + tx = comPos.X + (tx - comPos.X) * loT; + tz = comPos.Z + (tz - comPos.Z) * loT; + tgtHit = SampleGroundAt(terrain, world, tx, tz, comPos.Y + 0.8f); + } Vector3 tgtSole = new(tx, tgtHit.SurfaceY, tz); if (ClampSoleToReach(reachHip, geom.Legs[i].AnkleH * scale, geom.Legs[i].MaxLegReach * scale * 0.965f, reachCenter, terrain, world, comPos.Y + 0.8f, ref tgtSole, out Vector3 tgtNorm)) { @@ -1761,18 +1856,52 @@ namespace RustToDust.Ymir 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); var underHit = SampleGroundAt(terrain, world, sx, sz, comPos.Y + 0.8f); - float minGround = underHit.SurfaceY + 0.10f * scale * legEnv; + float maxSwingStep = MathF.Min(1.48f * MathF.Max(1f, scale), MathF.Max(0.95f * scale, horizSpeed * dt * 2.15f)); + 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); Vector3 swingStep = desiredSole - ws.FootSole[i]; float swingStepLen = swingStep.Length(); - float maxSwingStep = MathF.Max(1.50f * scale, horizSpeed * dt * 4.5f); if (swingStepLen > maxSwingStep && swingStepLen > 1e-5f) { Vector3 cappedSole = ws.FootSole[i] + swingStep * (maxSwingStep / swingStepLen); var capHit = SampleGroundAt(terrain, world, cappedSole.X, cappedSole.Z, comPos.Y + 0.8f); if (cappedSole.Y < capHit.SurfaceY) { - cappedSole.Y = capHit.SurfaceY; + if (capHit.SurfaceY <= ws.FootSole[i].Y + maxSwingStep * 0.92f) + { + cappedSole.Y = capHit.SurfaceY; + Vector3 dCap = cappedSole - ws.FootSole[i]; + if (dCap.Length() > maxSwingStep * 1.04f) + { + float dy = cappedSole.Y - ws.FootSole[i].Y; + float remH = MathF.Sqrt(MathF.Max(0.001f, maxSwingStep * maxSwingStep - dy * dy)); + float curH = MathF.Sqrt(dCap.X * dCap.X + dCap.Z * dCap.Z); + if (curH > remH && curH > 1e-4f) + { + cappedSole.X = ws.FootSole[i].X + dCap.X * (remH / curH); + cappedSole.Z = ws.FootSole[i].Z + dCap.Z * (remH / curH); + var reHit = SampleGroundAt(terrain, world, cappedSole.X, cappedSole.Z, comPos.Y + 0.8f); + if (reHit.SurfaceY <= ws.FootSole[i].Y + maxSwingStep * 0.96f) + { + cappedSole.Y = MathF.Max(cappedSole.Y, reHit.SurfaceY); + } + } + } + } + else + { + Vector3 toCom = new(comPos.X - ws.FootSole[i].X, 0f, comPos.Z - ws.FootSole[i].Z); + float toComLen = toCom.Length(); + cappedSole = toComLen > 1e-4f + ? ws.FootSole[i] + toCom * MathF.Min(0.25f, (maxSwingStep * 0.5f) / toComLen) + : ws.FootSole[i]; + var inHit = SampleGroundAt(terrain, world, cappedSole.X, cappedSole.Z, comPos.Y + 0.8f); + if (inHit.SurfaceY <= ws.FootSole[i].Y + maxSwingStep * 0.92f) + { + cappedSole.Y = MathF.Max(cappedSole.Y, inHit.SurfaceY); + } + } } ws.FootSole[i] = cappedSole; } @@ -1819,7 +1948,7 @@ namespace RustToDust.Ymir float slopeAdjY = Math.Clamp((minSoleY - centerG.SurfaceY) * 0.65f, -0.45f * scale, 0.05f * scale); float sprintCrouchFrac = Math.Clamp(horizSpeed / MathF.Max(5f, grid.Spec.MaxSpeed * 0.35f), 0f, 1f); - float sprintCrouchCoeff = 0.055f + 0.072f * straightness; + float sprintCrouchCoeff = 0.042f + 0.042f * straightness; float sprintCrouchY = -sprintCrouchCoeff * geom.ModelHalfHeight * scale * sprintCrouchFrac; float vaultAmp = Math.Clamp((0.042f + 0.015f * straightness) * rideHeight, 0.12f * scale, 0.25f * scale) * (0.40f + 0.60f * speedFrac); float vaultY = (swingSin - 0.15f * straightness) * vaultAmp; @@ -1989,16 +2118,40 @@ namespace RustToDust.Ymir Vector3 oldSole = ws.FootSole[i]; 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)) + Vector3 oldAnkle = oldSole + ws.FootNormal[i] * ankleH; + if ((oldAnkle - hipTotalW).Length() > maxReach) { - 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) + Vector3 clampedSole = oldSole; + bool changed = ClampSoleToReach(hipTotalW, ankleH, maxReach, comPos, terrain, world, comPos.Y + 0.8f, ref clampedSole, out Vector3 clampedN); + Vector3 slipVec = clampedSole - oldSole; + if (changed && slipVec.Length() <= 0.35f * MathF.Max(1f, scale) && MathF.Abs(slipVec.Y) <= 0.25f * MathF.Max(1f, scale)) { - ws.MaxFootSlipM = drag; + ws.FootSole[i] = clampedSole; + ws.FootNormal[i] = clampedN; + float drag = MathF.Sqrt(slipVec.X * slipVec.X + slipVec.Z * slipVec.Z); + if (drag > ws.MaxFootSlipM) + { + ws.MaxFootSlipM = drag; + } + } + else if (changed) + { + // Discontinuity (cliff/curb ledge) exceeds smooth slip: unplant and retract smoothly instead of snapping + ws.Planted[i] = false; + ws.SwingStartSole[i] = oldSole; + ws.SwingStartNormal[i] = ws.FootNormal[i]; + float maxUnplantStep = 0.38f * MathF.Max(1f, scale); + float slipLen = slipVec.Length(); + Vector3 nextSole = slipLen > maxUnplantStep && slipLen > 1e-5f + ? oldSole + slipVec * (maxUnplantStep / slipLen) + : clampedSole; + 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); + ws.FootNormal[i] = pNorm; + } + ws.FootSole[i] = nextSole; } } } @@ -2016,17 +2169,7 @@ namespace RustToDust.Ymir : maxReach; Vector3 clampedAnkle = hipTotalW + delta * (targetDist / 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 > targetDist && cdLen > 1e-5f) - { - clampedSole = (hipTotalW + cd * (targetDist / cdLen)) - under.Normal * ankleH; - } - } + ProjectSoleAboveGroundWithinReach(hipTotalW, ankleH, targetDist, terrain, world, comPos.Y + 0.8f, 0f, ref clampedSole, out _); ws.FootSole[i] = clampedSole; } } @@ -2040,12 +2183,12 @@ namespace RustToDust.Ymir float subDt = dt * 0.25f; float limbI = MathF.Max(1f, mass * scale * scale * 0.025f); - float kpStance = limbI * (n == 4 ? 4600f : 5600f); - float kpSwing = limbI * (n == 4 ? 3600f : 4400f); - float kdStance = limbI * (2f * 0.85f * MathF.Sqrt(n == 4 ? 4600f : 5600f)); - float kdSwing = limbI * (2f * 0.85f * MathF.Sqrt(n == 4 ? 3600f : 4400f)); + float kpStance = limbI * 5600f; + float kpSwing = limbI * 4400f; + float kdStance = limbI * (2f * 0.85f * MathF.Sqrt(5600f)); + float kdSwing = limbI * (2f * 0.85f * MathF.Sqrt(4400f)); float tauLimitBase = limbI * 700f; - float tauLimitAnkle = limbI * 650f; + float tauLimitAnkle = limbI * 1500f; float impactSpike = Math.Clamp(-ws.CompressionVelY * 0.55f, 0f, 1.4f); @@ -2061,27 +2204,29 @@ namespace RustToDust.Ymir float kd = planted ? kdStance : kdSwing; float tauMax = tauLimitBase * legIntegrities[i]; float tauAnkleMax = tauLimitAnkle * legIntegrities[i]; - // Arachnid-up KneeFlex rotates 2x HipPitch (2*alpha vs alpha) during rapid extension; track cleanly so shin does not plunge - float kpKnee = geom.IsArachnidUp ? kp * 1.25f : kp; - float kdKnee = geom.IsArachnidUp ? kd * 1.12f : kd; - float tauKnee = geom.IsArachnidUp ? tauMax * 1.25f : tauMax; + float kpSecondary = kp * 2.0f; + float kdSecondary = kd * 1.414f; + float tauSecondary = tauMax * 2.4f; + float kpKnee = geom.IsArachnidUp ? kp * 1.35f : kpSecondary; + float kdKnee = geom.IsArachnidUp ? kd * 1.16f : kdSecondary; + float tauKnee = geom.IsArachnidUp ? tauMax * 1.35f : tauSecondary; ref var act = ref ws.Actuators[i]; for (int sub = 0; sub < 4; sub++) { StepDof(ref act.Theta.HipPitch, ref act.Omega.HipPitch, target.HipPitch, kp, kd, tauMax, limbI, 0f, subDt); - StepDof(ref act.Theta.HipRoll, ref act.Omega.HipRoll, target.HipRoll, kp, kd, tauMax, limbI, 0f, subDt); + StepDof(ref act.Theta.HipRoll, ref act.Omega.HipRoll, target.HipRoll, kpSecondary, kdSecondary, tauSecondary, limbI, 0f, subDt); StepDof(ref act.Theta.KneeFlex, ref act.Omega.KneeFlex, target.KneeFlex, kpKnee, kdKnee, tauKnee, limbI, 0f, subDt); if (geom.IsDigitigrade) { - StepDof(ref act.Theta.HockFlex, ref act.Omega.HockFlex, target.HockFlex, kp, kd, tauMax, limbI, 0f, subDt); + StepDof(ref act.Theta.HockFlex, ref act.Omega.HockFlex, target.HockFlex, kpSecondary, kdSecondary, tauSecondary, limbI, 0f, subDt); } else { act.Theta.HockFlex = 0f; act.Omega.HockFlex = 0f; } - StepDof(ref act.Theta.AnklePitch, ref act.Omega.AnklePitch, target.AnklePitch, kp, kd, tauAnkleMax, limbI, 0f, subDt); + StepDof(ref act.Theta.AnklePitch, ref act.Omega.AnklePitch, target.AnklePitch, kpSecondary, kdSecondary, tauAnkleMax, limbI, 0f, subDt); } if (!ws.Grounded || !planted) @@ -2264,19 +2409,74 @@ 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; - if (sphereSole.Y < underSphere.SurfaceY) + ProjectSoleAboveGroundWithinReach(hipWorld, ankleH, maxReach, terrain, world, referenceMaxY, 0f, ref sphereSole, out normal); + sole = sphereSole; + return true; + } + + private static void ProjectSoleAboveGroundWithinReach( + Vector3 hipWorld, + float ankleH, + float maxReach, + TerrainField terrain, + Box3DSoaWorld? world, + float referenceMaxY, + float clearance, + ref Vector3 sole, + out Vector3 normal) + { + var under = SampleGroundAt(terrain, world, sole.X, sole.Z, referenceMaxY); + float minY = under.SurfaceY + clearance; + if (sole.Y >= minY) { - sphereSole.Y = underSphere.SurfaceY; - Vector3 cd = (sphereSole + underSphere.Normal * ankleH) - hipWorld; - float cdLen = cd.Length(); - if (cdLen > maxReach && cdLen > 1e-5f) + normal = under.Normal; + return; + } + + sole.Y = minY; + for (int iter = 0; iter < 4; iter++) + { + Vector3 ank = sole + under.Normal * ankleH; + Vector3 d = ank - hipWorld; + if (d.Length() <= maxReach) { - sphereSole = (hipWorld + cd * (maxReach / cdLen)) - underSphere.Normal * ankleH; + break; + } + + 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 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) + { + 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; + } + else + { + // Ground at sole XZ lies above hip upper sphere: step horizontally inward toward hipWorld + sole.X += (hipWorld.X - sole.X) * 0.35f; + sole.Z += (hipWorld.Z - sole.Z) * 0.35f; + under = SampleGroundAt(terrain, world, sole.X, sole.Z, referenceMaxY); + sole.Y = under.SurfaceY + clearance; } } - sole = sphereSole; - normal = underSphere.Normal; - return true; + + under = SampleGroundAt(terrain, world, sole.X, sole.Z, referenceMaxY); + if (sole.Y < under.SurfaceY + clearance) + { + sole.Y = under.SurfaceY + clearance; + } + normal = under.Normal; } public static WalkerLegAngles SolveLegTargetAngles( diff --git a/tests/RustToDust.Tests/HybridBWalkerTests.cs b/tests/RustToDust.Tests/HybridBWalkerTests.cs index b9b09cd..d0f6cb6 100644 --- a/tests/RustToDust.Tests/HybridBWalkerTests.cs +++ b/tests/RustToDust.Tests/HybridBWalkerTests.cs @@ -1578,10 +1578,13 @@ namespace RustToDust.Tests var grid = new ChassisGrid(spec); var ws = new WalkerState(spec); ws.InitializePose(new Vector3(0f, spawnY, -4f), Quaternion.Identity, world.View.Mass[body.Lane], terrain, world, body.Lane); + Vector3[] prevSoles = new Vector3[ws.Geom.LegCount]; + for (int i = 0; i < ws.Geom.LegCount; i++) prevSoles[i] = ws.FootSole[i]; float maxVelY = float.NegativeInfinity; float minVelY = float.PositiveInfinity; float maxReachedY = 0f; + float maxCurbFootJump = 0f; bool sawCliffFall = false; bool sawCliffLandingDip = false; var view = world.View; @@ -1600,6 +1603,12 @@ namespace RustToDust.Tests maxVelY = MathF.Max(maxVelY, vy); minVelY = MathF.Min(minVelY, vy); maxReachedY = MathF.Max(maxReachedY, view.PositionY[lane]); + for (int i = 0; i < ws.Geom.LegCount; i++) + { + float j = Vector3.Distance(ws.FootSole[i], prevSoles[i]); + if (j > maxCurbFootJump) maxCurbFootJump = j; + prevSoles[i] = ws.FootSole[i]; + } if (view.PositionZ[lane] > 56f && ws.IsAirborne) { @@ -1613,11 +1622,12 @@ namespace RustToDust.Tests _output.WriteLine( $"{spec.Id,-10} curbs 0.30/0.45/0.60m + 3m cliff: endZ={view.PositionZ[lane]:F1}m maxY={maxReachedY:F2}m " + - $"maxVy={maxVelY:F2}m/s minVy={minVelY:F2}m/s cliffFall={sawCliffFall} landingDip={sawCliffLandingDip}"); + $"maxVy={maxVelY:F2}m/s minVy={minVelY:F2}m/s maxFootJump={maxCurbFootJump:F3}m cliffFall={sawCliffFall} landingDip={sawCliffLandingDip}"); Assert.True(view.PositionZ[lane] > 58f, $"{spec.Id}: stalled on 0.30-0.60m curbs (endZ={view.PositionZ[lane]:F1}m)"); Assert.True(maxReachedY >= 3.0f + 0.55f + capR + capHalfL - 0.05f, $"{spec.Id}: failed to climb 0.60m curb (maxY={maxReachedY:F2}m)"); Assert.True(maxVelY <= 2.5f, $"{spec.Id}: curb catapult detected! maxVelY={maxVelY:F2}m/s > 2.5m/s"); + Assert.True(maxCurbFootJump < 1.65f, $"{spec.Id}: curb/cliff 1-tick foot teleport {maxCurbFootJump:F3}m >= 1.65m"); Assert.True(sawCliffFall && minVelY < -3.0f, $"{spec.Id}: failed ballistic freefall off 3m cliff (minVelY={minVelY:F2})"); Assert.True(sawCliffLandingDip, $"{spec.Id}: expected CompressionY landing dip after 3m cliff drop"); } @@ -1920,9 +1930,9 @@ namespace RustToDust.Tests float footDelta = Vector3.Distance(sole, prevSoles[i]); float maxAllowedDelta = (wasAirborne || ws.IsAirborne) ? 1.25f * MathF.Max(1f, ws.GeomScale) - : MathF.Max(1.65f * ws.GeomScale, spec.MaxSpeed * ArenaSession.FixedDt * 4.2f); - Assert.True(footDelta <= maxAllowedDelta, - $"{spec.Id} ({map}) tick {t} leg {i}: foot teleport delta {footDelta:F3}m > {maxAllowedDelta:F3}m"); + : 1.65f * MathF.Max(1f, ws.GeomScale); + Assert.True(footDelta < maxAllowedDelta, + $"{spec.Id} ({map}) tick {t} leg {i}: foot teleport delta {footDelta:F3}m >= {maxAllowedDelta:F3}m"); prevSoles[i] = sole; } @@ -2008,50 +2018,85 @@ namespace RustToDust.Tests Assert.True(dist3D <= reachLimit, $"{spec.Id} Sion steep slope tick {t} leg {i}: 3D reach overflow {dist3D:F3} > {reachLimit:F3}"); + float soleGroundY = sionSession.QueryDropSurface(ws.FootSole[i].X, ws.FootSole[i].Z, 0f, comPos.Y + 1.0f).SurfaceY; + float soleRel = ws.FootSole[i].Y - soleGroundY; + Assert.True(soleRel >= -0.20f, + $"{spec.Id} Sion steep slope tick {t} leg {i}: sole plunged underground {soleRel:F3}m"); + float footJump = Vector3.Distance(ws.FootSole[i], prevSoles[i]); - float maxJump = MathF.Max(1.65f * ws.GeomScale, spec.MaxSpeed * ArenaSession.FixedDt * 4.2f); - Assert.True(footJump <= maxJump, - $"{spec.Id} Sion steep slope tick {t} leg {i}: teleport jump {footJump:F3}m > {maxJump:F3}m"); + float maxJump = 1.65f * MathF.Max(1f, ws.GeomScale); + Assert.True(footJump < maxJump, + $"{spec.Id} Sion steep slope tick {t} leg {i}: teleport jump {footJump:F3}m >= {maxJump:F3}m"); prevSoles[i] = ws.FootSole[i]; } } } - // 2. Kestrel sprinting straight uphill on steep Sion hill must stay grounded (no false blast launch from slopeVy) - 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 kestrel = sionSession.State.Contenders[0]; - var kBody = sionSession.GetContenderBody(kestrel.Id)!.Value; - var kWs = sionSession.GetWalkerState(true, kestrel.Id)!; - var kView = sionSession.World.View; - int kLane = kBody.Lane; - int airborneTicks = 0; - float maxVelY = 0f; - float maxAboveGround = 0f; - - for (int t = 0; t < 100; t++) + // 2. Kestrel + Spectre + ExemplarFrame sprinting across Sion curbs/hills must stay grounded with zero non-blast launches & < 1.65m foot deltas + foreach (var sprintSpec in new[] { Catalog.Kestrel, Catalog.Spectre, ExemplarFrame }) { - var (nx, ny, nz) = sionSession.State.Terrain.SampleNormal(kestrel.X, kestrel.Z); - float upYaw = (ny < 0.995f) ? MathF.Atan2(-nx, -nz) : steepSite.Yaw; - sionSession.SetHumanInput(0, new PlayerInput( - 1.0f, 0f, - kestrel.X + 40f * MathF.Sin(upYaw), - kestrel.Z + 40f * MathF.Cos(upYaw), - false, false, false)); - sionSession.Step(); + bool isSteepTest = sprintSpec.Id == "kestrel"; + float startX = isSteepTest ? steepSite.X : 0f; + float startZ = isSteepTest ? steepSite.Z : -15f; + float startYaw = isSteepTest ? steepSite.Yaw : 0f; + sionSession.SetContenderPose(0, startX, startZ, startYaw); + sionSession.State.SpawnChassisDrop(startX, startZ, sprintSpec); + Assert.True(sionSession.TrySwapNearbyChassis(0)); + sionSession.SetContenderPose(0, startX, startZ, startYaw); - if (kWs.IsAirborne) airborneTicks++; - maxVelY = MathF.Max(maxVelY, kView.VelocityY[kLane]); - float surfY = sionSession.State.Terrain.SampleHeight(kestrel.X, kestrel.Z); - maxAboveGround = MathF.Max(maxAboveGround, kestrel.Y - (surfY + MatchRules.GetRideHeight(Catalog.Kestrel))); + var contender = sionSession.State.Contenders[0]; + var cBody = sionSession.GetContenderBody(contender.Id)!.Value; + var cWs = sionSession.GetWalkerState(true, contender.Id)!; + var cView = sionSession.World.View; + int cLane = cBody.Lane; + int airborneTicks = 0; + float maxVelY = 0f; + float maxAboveGround = 0f; + float maxFootJump = 0f; + float minSoleRel = float.PositiveInfinity; + var prevSprintSoles = new Vector3[cWs.Geom.LegCount]; + for (int i = 0; i < prevSprintSoles.Length; i++) prevSprintSoles[i] = cWs.FootSole[i]; + + 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; + } + sionSession.SetHumanInput(0, new PlayerInput( + 1.0f, + isSteepTest ? 0f : MathF.Sin(t * 0.07f) * 0.45f, + contender.X + 40f * MathF.Sin(aimYaw), + contender.Z + 40f * MathF.Cos(aimYaw), + false, false, false)); + sionSession.Step(); + + if (cWs.IsAirborne) airborneTicks++; + maxVelY = MathF.Max(maxVelY, cView.VelocityY[cLane]); + float surfY = sionSession.QueryDropSurface(contender.X, contender.Z, 0f, contender.Y + 1.0f).SurfaceY; + maxAboveGround = MathF.Max(maxAboveGround, contender.Y - (surfY + MatchRules.GetRideHeight(sprintSpec))); + for (int i = 0; i < cWs.Geom.LegCount; i++) + { + float j = Vector3.Distance(cWs.FootSole[i], prevSprintSoles[i]); + if (j > maxFootJump) maxFootJump = j; + prevSprintSoles[i] = cWs.FootSole[i]; + float sY = sionSession.QueryDropSurface(cWs.FootSole[i].X, cWs.FootSole[i].Z, 0f, contender.Y + 1.0f).SurfaceY; + minSoleRel = MathF.Min(minSoleRel, cWs.FootSole[i].Y - sY); + } + } + + Assert.True(airborneTicks <= 3, $"{sprintSpec.Id} Sion sprint false-launched for {airborneTicks}/120 ticks!"); + Assert.True(maxVelY < 9.5f, $"{sprintSpec.Id} Sion sprint maxVelY spiked to {maxVelY:F2} m/s"); + Assert.True(maxAboveGround < 0.85f, $"{sprintSpec.Id} Sion sprint lifted {maxAboveGround:F2}m above ride height"); + Assert.True(maxFootJump < 1.65f * MathF.Max(1f, cWs.GeomScale), $"{sprintSpec.Id} Sion sprint foot teleport {maxFootJump:F3}m >= 1.65m"); + Assert.True(minSoleRel >= -0.20f, $"{sprintSpec.Id} Sion sprint sole underground {minSoleRel:F3}m < -0.20m"); } - - Assert.True(airborneTicks <= 3, $"Kestrel uphill sprint false-launched for {airborneTicks}/100 ticks!"); - Assert.True(maxVelY < 9.5f, $"Kestrel uphill sprint maxVelY spiked to {maxVelY:F2} m/s"); - Assert.True(maxAboveGround < 0.85f, $"Kestrel uphill sprint lifted {maxAboveGround:F2}m above ride height"); } // 3. Low upward splash impulse (< 3.5 m/s) must NOT be zeroed out on tick 1