cut11b: fix Soul Pass #2 foot ground clamp, curb teleports, Sion launches, and Smoke clearances
This commit is contained in:
parent
dc1df6041c
commit
3964017458
5 changed files with 402 additions and 135 deletions
|
|
@ -200,8 +200,7 @@ public sealed class VehicleVisualInstance
|
||||||
bool isWalker = role != VehicleVisualRole.SalvageDrop &&
|
bool isWalker = role != VehicleVisualRole.SalvageDrop &&
|
||||||
(pkg.Mobility == MobilityKind.Walker ||
|
(pkg.Mobility == MobilityKind.Walker ||
|
||||||
pkg.Plane == GridPlane.Coronal ||
|
pkg.Plane == GridPlane.Coronal ||
|
||||||
string.Equals(pkg.Id, "manticore", StringComparison.OrdinalIgnoreCase) ||
|
WalkerGeometrySpec.TryGetForChassis(pkg.Id, out _));
|
||||||
string.Equals(pkg.Id, "bastion", StringComparison.OrdinalIgnoreCase));
|
|
||||||
float groundOffset = isWalker
|
float groundOffset = isWalker
|
||||||
? WalkerGeometrySpec.GetForChassis(pkg.Id).ModelRideHeight * effectiveScale
|
? WalkerGeometrySpec.GetForChassis(pkg.Id).ModelRideHeight * effectiveScale
|
||||||
: halfHeight;
|
: halfHeight;
|
||||||
|
|
|
||||||
|
|
@ -127,8 +127,7 @@ namespace RustToDust.Core
|
||||||
public bool IsWalker =>
|
public bool IsWalker =>
|
||||||
Mobility == MobilityKind.Walker ||
|
Mobility == MobilityKind.Walker ||
|
||||||
Plane == GridPlane.Coronal ||
|
Plane == GridPlane.Coronal ||
|
||||||
string.Equals(Id, "manticore", StringComparison.OrdinalIgnoreCase) ||
|
WalkerGeometrySpec.TryGetForChassis(Id, out _);
|
||||||
string.Equals(Id, "bastion", StringComparison.OrdinalIgnoreCase);
|
|
||||||
|
|
||||||
public bool IsVtol => Mobility == MobilityKind.Vtol;
|
public bool IsVtol => Mobility == MobilityKind.Vtol;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -139,19 +139,43 @@ namespace RustToDust.Core
|
||||||
public static readonly WalkerGeometrySpec Manticore = BuildManticore();
|
public static readonly WalkerGeometrySpec Manticore = BuildManticore();
|
||||||
public static readonly WalkerGeometrySpec Bastion = BuildBastion();
|
public static readonly WalkerGeometrySpec Bastion = BuildBastion();
|
||||||
|
|
||||||
public static WalkerGeometrySpec GetForChassis(string chassisId) =>
|
public static bool TryGetForChassis(string? chassisId, out WalkerGeometrySpec spec)
|
||||||
chassisId.ToLowerInvariant() switch
|
{
|
||||||
|
switch (chassisId?.ToLowerInvariant())
|
||||||
{
|
{
|
||||||
"breaker" => Breaker,
|
case "breaker":
|
||||||
"paladin" => Paladin,
|
spec = Breaker;
|
||||||
"raptor" => Raptor,
|
return true;
|
||||||
"exemplar_frame" => Raptor,
|
case "paladin":
|
||||||
"spectre" => Spectre,
|
spec = Paladin;
|
||||||
"kestrel" => Kestrel,
|
return true;
|
||||||
"manticore" => Manticore,
|
case "raptor":
|
||||||
"bastion" => Bastion,
|
case "exemplar_frame":
|
||||||
_ => Raptor
|
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()
|
private static WalkerGeometrySpec BuildBreaker()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ namespace RustToDust.Ymir
|
||||||
public bool PostStepGrounded;
|
public bool PostStepGrounded;
|
||||||
public bool PendingExternalImpulse;
|
public bool PendingExternalImpulse;
|
||||||
public bool PreStepHadUpwardImpulse;
|
public bool PreStepHadUpwardImpulse;
|
||||||
|
public bool InExternalBlastArc;
|
||||||
public Vector3 PrevHorizVel;
|
public Vector3 PrevHorizVel;
|
||||||
public float MaxFootSlipM;
|
public float MaxFootSlipM;
|
||||||
public Vector3 PelvisOffset;
|
public Vector3 PelvisOffset;
|
||||||
|
|
@ -86,6 +87,7 @@ namespace RustToDust.Ymir
|
||||||
public bool PostStepGrounded;
|
public bool PostStepGrounded;
|
||||||
public bool PendingExternalImpulse;
|
public bool PendingExternalImpulse;
|
||||||
public bool PreStepHadUpwardImpulse;
|
public bool PreStepHadUpwardImpulse;
|
||||||
|
public bool InExternalBlastArc;
|
||||||
public Vector3 PrevHorizVel;
|
public Vector3 PrevHorizVel;
|
||||||
public float MaxFootSlipM;
|
public float MaxFootSlipM;
|
||||||
public Vector3 PelvisOffset;
|
public Vector3 PelvisOffset;
|
||||||
|
|
@ -257,6 +259,7 @@ namespace RustToDust.Ymir
|
||||||
|
|
||||||
CurrSnap = BuildSnapshot(comPos, qYaw, mass);
|
CurrSnap = BuildSnapshot(comPos, qYaw, mass);
|
||||||
PrevSnap = CurrSnap;
|
PrevSnap = CurrSnap;
|
||||||
|
InExternalBlastArc = false;
|
||||||
Initialized = true;
|
Initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -285,6 +288,7 @@ namespace RustToDust.Ymir
|
||||||
PostStepGrounded = PostStepGrounded,
|
PostStepGrounded = PostStepGrounded,
|
||||||
PendingExternalImpulse = PendingExternalImpulse,
|
PendingExternalImpulse = PendingExternalImpulse,
|
||||||
PreStepHadUpwardImpulse = PreStepHadUpwardImpulse,
|
PreStepHadUpwardImpulse = PreStepHadUpwardImpulse,
|
||||||
|
InExternalBlastArc = InExternalBlastArc,
|
||||||
PrevHorizVel = PrevHorizVel,
|
PrevHorizVel = PrevHorizVel,
|
||||||
MaxFootSlipM = MaxFootSlipM,
|
MaxFootSlipM = MaxFootSlipM,
|
||||||
PelvisOffset = PelvisOffset,
|
PelvisOffset = PelvisOffset,
|
||||||
|
|
@ -329,6 +333,7 @@ namespace RustToDust.Ymir
|
||||||
PostStepGrounded = cp.PostStepGrounded;
|
PostStepGrounded = cp.PostStepGrounded;
|
||||||
PendingExternalImpulse = cp.PendingExternalImpulse;
|
PendingExternalImpulse = cp.PendingExternalImpulse;
|
||||||
PreStepHadUpwardImpulse = cp.PreStepHadUpwardImpulse;
|
PreStepHadUpwardImpulse = cp.PreStepHadUpwardImpulse;
|
||||||
|
InExternalBlastArc = cp.InExternalBlastArc;
|
||||||
PrevHorizVel = cp.PrevHorizVel;
|
PrevHorizVel = cp.PrevHorizVel;
|
||||||
MaxFootSlipM = cp.MaxFootSlipM;
|
MaxFootSlipM = cp.MaxFootSlipM;
|
||||||
PelvisOffset = cp.PelvisOffset;
|
PelvisOffset = cp.PelvisOffset;
|
||||||
|
|
@ -386,6 +391,7 @@ namespace RustToDust.Ymir
|
||||||
{
|
{
|
||||||
PendingExternalImpulse = true;
|
PendingExternalImpulse = true;
|
||||||
PreStepHadUpwardImpulse = true;
|
PreStepHadUpwardImpulse = true;
|
||||||
|
InExternalBlastArc = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool aboveGround = (comPos.Y - rideH) > gCenter.SurfaceY + 0.18f;
|
bool aboveGround = (comPos.Y - rideH) > gCenter.SurfaceY + 0.18f;
|
||||||
|
|
@ -406,6 +412,7 @@ namespace RustToDust.Ymir
|
||||||
IsAirborne = true;
|
IsAirborne = true;
|
||||||
PendingExternalImpulse = hasUpwardBlast;
|
PendingExternalImpulse = hasUpwardBlast;
|
||||||
PreStepHadUpwardImpulse = hasUpwardBlast;
|
PreStepHadUpwardImpulse = hasUpwardBlast;
|
||||||
|
InExternalBlastArc = hasUpwardBlast;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -670,6 +677,14 @@ namespace RustToDust.Ymir
|
||||||
ws.WasGrounded = ws.Grounded;
|
ws.WasGrounded = ws.Grounded;
|
||||||
bool externalImpulse = ws.PendingExternalImpulse || (ws.PostStepGrounded && vel.Y > ws.PostStepVelY + 0.65f);
|
bool externalImpulse = ws.PendingExternalImpulse || (ws.PostStepGrounded && vel.Y > ws.PostStepVelY + 0.65f);
|
||||||
ws.PreStepHadUpwardImpulse = externalImpulse;
|
ws.PreStepHadUpwardImpulse = externalImpulse;
|
||||||
|
if (externalImpulse)
|
||||||
|
{
|
||||||
|
ws.InExternalBlastArc = true;
|
||||||
|
}
|
||||||
|
else if (ws.Grounded)
|
||||||
|
{
|
||||||
|
ws.InExternalBlastArc = false;
|
||||||
|
}
|
||||||
ws.PendingExternalImpulse = false;
|
ws.PendingExternalImpulse = false;
|
||||||
ws.PrevHorizVel = new Vector3(vel.X, 0f, vel.Z);
|
ws.PrevHorizVel = new Vector3(vel.X, 0f, vel.Z);
|
||||||
ws.PrevVelY = vel.Y;
|
ws.PrevVelY = vel.Y;
|
||||||
|
|
@ -774,13 +789,35 @@ 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;
|
||||||
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.ForceX[lane] = 0f;
|
||||||
view.ForceY[lane] = mass * WalkerState.ArenaGravity;
|
view.ForceY[lane] = mass * WalkerState.ArenaGravity;
|
||||||
view.ForceZ[lane] = 0f;
|
view.ForceZ[lane] = 0f;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (!airborneImpulse && !ws.InExternalBlastArc && targetVy > 0.25f)
|
||||||
|
{
|
||||||
|
targetVy = 0.25f;
|
||||||
|
}
|
||||||
view.ForceX[lane] = 0f;
|
view.ForceX[lane] = 0f;
|
||||||
view.ForceY[lane] = 0f;
|
view.ForceY[lane] = 0f;
|
||||||
view.ForceZ[lane] = 0f;
|
view.ForceZ[lane] = 0f;
|
||||||
|
|
@ -1063,11 +1100,11 @@ namespace RustToDust.Ymir
|
||||||
ws.DidStepUp = false;
|
ws.DidStepUp = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1b. Suppress spurious Box3D curb/corner solver launch when grounded without external upward impulse
|
// 1b. Suppress spurious Box3D curb/corner solver launch when not on an explicit external blast
|
||||||
if (!ws.PreStepHadUpwardImpulse && ws.WasGrounded && vel.Y > 0.25f)
|
if (!ws.PreStepHadUpwardImpulse && !ws.InExternalBlastArc && vel.Y > 0.25f)
|
||||||
{
|
{
|
||||||
float maxSlopeVy = ws.GroundNormal.Y >= WalkerState.MaxCliffGuardNormalY
|
float maxSlopeVy = ws.WasGrounded && ws.GroundNormal.Y >= WalkerState.MaxCliffGuardNormalY
|
||||||
? MathF.Max(0f, -(vel.X * ws.GroundNormal.X + vel.Z * ws.GroundNormal.Z) / ws.GroundNormal.Y) + 0.25f
|
? Math.Clamp(-(vel.X * ws.GroundNormal.X + vel.Z * ws.GroundNormal.Z) / ws.GroundNormal.Y + 0.25f, 0.25f, 9.25f)
|
||||||
: 0.25f;
|
: 0.25f;
|
||||||
if (vel.Y > maxSlopeVy)
|
if (vel.Y > maxSlopeVy)
|
||||||
{
|
{
|
||||||
|
|
@ -1214,10 +1251,15 @@ namespace RustToDust.Ymir
|
||||||
ws.GroundNormal = gTerrN;
|
ws.GroundNormal = gTerrN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ws.Grounded && !ws.PreStepHadUpwardImpulse && vel.Y > 0.25f)
|
if (ws.Grounded && !ws.PreStepHadUpwardImpulse)
|
||||||
{
|
{
|
||||||
float maxSlopeVy = ws.GroundNormal.Y >= WalkerState.MaxWalkableNormalY
|
ws.InExternalBlastArc = false;
|
||||||
? MathF.Max(0f, -(vel.X * ws.GroundNormal.X + vel.Z * ws.GroundNormal.Z) / ws.GroundNormal.Y) + 0.25f
|
}
|
||||||
|
|
||||||
|
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;
|
: 0.25f;
|
||||||
if (vel.Y > maxSlopeVy)
|
if (vel.Y > maxSlopeVy)
|
||||||
{
|
{
|
||||||
|
|
@ -1416,21 +1458,8 @@ namespace RustToDust.Ymir
|
||||||
? carriedFoot + diff * (maxLocalRetract / diffLen)
|
? carriedFoot + diff * (maxLocalRetract / diffLen)
|
||||||
: targetAirSole;
|
: targetAirSole;
|
||||||
|
|
||||||
var underHit = SampleGroundAt(terrain, world, nextSole.X, nextSole.Z, comPos.Y + 0.8f);
|
ProjectSoleAboveGroundWithinReach(hipAirW, ankleH, maxAirReach, terrain, world, comPos.Y + 0.8f, airClearance, ref nextSole, out Vector3 clampedAirN);
|
||||||
Vector3 nextNorm = underHit.Normal;
|
Vector3 nextNorm = clampedAirN;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ws.FootSole[i] = nextSole;
|
ws.FootSole[i] = nextSole;
|
||||||
ws.FootNormal[i] = Vector3.Normalize(Vector3.Lerp(ws.FootNormal[i], nextNorm, Math.Clamp(dt * 8f, 0f, 1f)));
|
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;
|
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);
|
landedSole = ws.FootSole[i] + landDelta * (maxLandJump / landDist);
|
||||||
Vector3 fallbackSole = new(ws.FootSole[i].X, curGround.SurfaceY, ws.FootSole[i].Z);
|
var capHit = SampleGroundAt(terrain, world, landedSole.X, landedSole.Z, comPos.Y + 0.8f);
|
||||||
Vector3 fallbackNorm = curGround.Normal;
|
landedNorm = capHit.Normal;
|
||||||
if (ClampSoleToReach(plantHip, plantAnkleH, plantMaxReach, comPos, terrain, world, comPos.Y + 0.8f, ref fallbackSole, out Vector3 fbClampedN))
|
if (landedSole.Y < capHit.SurfaceY)
|
||||||
{
|
{
|
||||||
fallbackNorm = fbClampedN;
|
if (capHit.SurfaceY <= ws.FootSole[i].Y + maxLandJump * 0.90f)
|
||||||
}
|
{
|
||||||
if ((fallbackSole - ws.FootSole[i]).Length() < (landedSole - ws.FootSole[i]).Length())
|
landedSole.Y = capHit.SurfaceY;
|
||||||
{
|
}
|
||||||
landedSole = fallbackSole;
|
else
|
||||||
landedNorm = fallbackNorm;
|
{
|
||||||
|
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);
|
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;
|
candTouchesGround[i] = touchesGround;
|
||||||
if (earlyBreak && ws.SwingPhase < 1.0f && !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 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 curHip = comPos + new Vector3(0f, -crouchBias, 0f) + Vector3.Transform(geom.Legs[i].HipInCom * scale, qYaw);
|
||||||
Vector3 reachHip = Vector3.Lerp(predHip, curHip, legUSwing);
|
Vector3 reachHip = Vector3.Lerp(predHip, curHip, legUSwing);
|
||||||
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;
|
||||||
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)
|
||||||
|
{
|
||||||
|
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);
|
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))
|
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 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 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 desiredSole = new(sx, MathF.Max(syBase + arcLift, minGround), sz);
|
||||||
Vector3 swingStep = desiredSole - ws.FootSole[i];
|
Vector3 swingStep = desiredSole - ws.FootSole[i];
|
||||||
float swingStepLen = swingStep.Length();
|
float swingStepLen = swingStep.Length();
|
||||||
float maxSwingStep = MathF.Max(1.50f * scale, horizSpeed * dt * 4.5f);
|
|
||||||
if (swingStepLen > maxSwingStep && swingStepLen > 1e-5f)
|
if (swingStepLen > maxSwingStep && swingStepLen > 1e-5f)
|
||||||
{
|
{
|
||||||
Vector3 cappedSole = ws.FootSole[i] + swingStep * (maxSwingStep / swingStepLen);
|
Vector3 cappedSole = ws.FootSole[i] + swingStep * (maxSwingStep / swingStepLen);
|
||||||
var capHit = SampleGroundAt(terrain, world, cappedSole.X, cappedSole.Z, comPos.Y + 0.8f);
|
var capHit = SampleGroundAt(terrain, world, cappedSole.X, cappedSole.Z, comPos.Y + 0.8f);
|
||||||
if (cappedSole.Y < capHit.SurfaceY)
|
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;
|
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 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 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 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 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;
|
float vaultY = (swingSin - 0.15f * straightness) * vaultAmp;
|
||||||
|
|
@ -1989,16 +2118,40 @@ namespace RustToDust.Ymir
|
||||||
Vector3 oldSole = ws.FootSole[i];
|
Vector3 oldSole = ws.FootSole[i];
|
||||||
if (ws.Grounded && ws.Planted[i])
|
if (ws.Grounded && ws.Planted[i])
|
||||||
{
|
{
|
||||||
Vector3 clampedSole = oldSole;
|
Vector3 oldAnkle = oldSole + ws.FootNormal[i] * ankleH;
|
||||||
if (ClampSoleToReach(hipTotalW, ankleH, maxReach, comPos, terrain, world, comPos.Y + 0.8f, ref clampedSole, out Vector3 clampedN))
|
if ((oldAnkle - hipTotalW).Length() > maxReach)
|
||||||
{
|
{
|
||||||
ws.FootSole[i] = clampedSole;
|
Vector3 clampedSole = oldSole;
|
||||||
ws.FootNormal[i] = clampedN;
|
bool changed = ClampSoleToReach(hipTotalW, ankleH, maxReach, comPos, terrain, world, comPos.Y + 0.8f, ref clampedSole, out Vector3 clampedN);
|
||||||
float drag = MathF.Sqrt((clampedSole.X - oldSole.X) * (clampedSole.X - oldSole.X) +
|
Vector3 slipVec = clampedSole - oldSole;
|
||||||
(clampedSole.Z - oldSole.Z) * (clampedSole.Z - oldSole.Z));
|
if (changed && slipVec.Length() <= 0.35f * MathF.Max(1f, scale) && MathF.Abs(slipVec.Y) <= 0.25f * MathF.Max(1f, scale))
|
||||||
if (drag > ws.MaxFootSlipM)
|
|
||||||
{
|
{
|
||||||
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;
|
: maxReach;
|
||||||
Vector3 clampedAnkle = hipTotalW + delta * (targetDist / dist);
|
Vector3 clampedAnkle = hipTotalW + delta * (targetDist / dist);
|
||||||
Vector3 clampedSole = clampedAnkle - ws.FootNormal[i] * ankleH;
|
Vector3 clampedSole = clampedAnkle - ws.FootNormal[i] * ankleH;
|
||||||
var under = SampleGroundAt(terrain, world, clampedSole.X, clampedSole.Z, comPos.Y + 0.8f);
|
ProjectSoleAboveGroundWithinReach(hipTotalW, ankleH, targetDist, terrain, world, comPos.Y + 0.8f, 0f, ref clampedSole, out _);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ws.FootSole[i] = clampedSole;
|
ws.FootSole[i] = clampedSole;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2040,12 +2183,12 @@ 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 kpStance = limbI * (n == 4 ? 4600f : 5600f);
|
float kpStance = limbI * 5600f;
|
||||||
float kpSwing = limbI * (n == 4 ? 3600f : 4400f);
|
float kpSwing = limbI * 4400f;
|
||||||
float kdStance = limbI * (2f * 0.85f * MathF.Sqrt(n == 4 ? 4600f : 5600f));
|
float kdStance = limbI * (2f * 0.85f * MathF.Sqrt(5600f));
|
||||||
float kdSwing = limbI * (2f * 0.85f * MathF.Sqrt(n == 4 ? 3600f : 4400f));
|
float kdSwing = limbI * (2f * 0.85f * MathF.Sqrt(4400f));
|
||||||
float tauLimitBase = limbI * 700f;
|
float tauLimitBase = limbI * 700f;
|
||||||
float tauLimitAnkle = limbI * 650f;
|
float tauLimitAnkle = limbI * 1500f;
|
||||||
|
|
||||||
float impactSpike = Math.Clamp(-ws.CompressionVelY * 0.55f, 0f, 1.4f);
|
float impactSpike = Math.Clamp(-ws.CompressionVelY * 0.55f, 0f, 1.4f);
|
||||||
|
|
||||||
|
|
@ -2061,27 +2204,29 @@ namespace RustToDust.Ymir
|
||||||
float kd = planted ? kdStance : kdSwing;
|
float kd = planted ? kdStance : kdSwing;
|
||||||
float tauMax = tauLimitBase * legIntegrities[i];
|
float tauMax = tauLimitBase * legIntegrities[i];
|
||||||
float tauAnkleMax = tauLimitAnkle * 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 kpSecondary = kp * 2.0f;
|
||||||
float kpKnee = geom.IsArachnidUp ? kp * 1.25f : kp;
|
float kdSecondary = kd * 1.414f;
|
||||||
float kdKnee = geom.IsArachnidUp ? kd * 1.12f : kd;
|
float tauSecondary = tauMax * 2.4f;
|
||||||
float tauKnee = geom.IsArachnidUp ? tauMax * 1.25f : tauMax;
|
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];
|
ref var act = ref ws.Actuators[i];
|
||||||
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, kp, kd, tauMax, limbI, 0f, subDt);
|
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);
|
StepDof(ref act.Theta.KneeFlex, ref act.Omega.KneeFlex, target.KneeFlex, kpKnee, kdKnee, tauKnee, limbI, 0f, subDt);
|
||||||
if (geom.IsDigitigrade)
|
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
|
else
|
||||||
{
|
{
|
||||||
act.Theta.HockFlex = 0f;
|
act.Theta.HockFlex = 0f;
|
||||||
act.Omega.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)
|
if (!ws.Grounded || !planted)
|
||||||
|
|
@ -2264,19 +2409,74 @@ namespace RustToDust.Ymir
|
||||||
: hipWorld - new Vector3(0f, maxReach, 0f);
|
: hipWorld - new Vector3(0f, maxReach, 0f);
|
||||||
var underSphere = SampleGroundAt(terrain, world, clampedAnkle.X, clampedAnkle.Z, referenceMaxY);
|
var underSphere = SampleGroundAt(terrain, world, clampedAnkle.X, clampedAnkle.Z, referenceMaxY);
|
||||||
Vector3 sphereSole = clampedAnkle - underSphere.Normal * ankleH;
|
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;
|
normal = under.Normal;
|
||||||
Vector3 cd = (sphereSole + underSphere.Normal * ankleH) - hipWorld;
|
return;
|
||||||
float cdLen = cd.Length();
|
}
|
||||||
if (cdLen > maxReach && cdLen > 1e-5f)
|
|
||||||
|
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;
|
under = SampleGroundAt(terrain, world, sole.X, sole.Z, referenceMaxY);
|
||||||
return true;
|
if (sole.Y < under.SurfaceY + clearance)
|
||||||
|
{
|
||||||
|
sole.Y = under.SurfaceY + clearance;
|
||||||
|
}
|
||||||
|
normal = under.Normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WalkerLegAngles SolveLegTargetAngles(
|
public static WalkerLegAngles SolveLegTargetAngles(
|
||||||
|
|
|
||||||
|
|
@ -1578,10 +1578,13 @@ namespace RustToDust.Tests
|
||||||
var grid = new ChassisGrid(spec);
|
var grid = new ChassisGrid(spec);
|
||||||
var ws = new WalkerState(spec);
|
var ws = new WalkerState(spec);
|
||||||
ws.InitializePose(new Vector3(0f, spawnY, -4f), Quaternion.Identity, world.View.Mass[body.Lane], terrain, world, body.Lane);
|
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 maxVelY = float.NegativeInfinity;
|
||||||
float minVelY = float.PositiveInfinity;
|
float minVelY = float.PositiveInfinity;
|
||||||
float maxReachedY = 0f;
|
float maxReachedY = 0f;
|
||||||
|
float maxCurbFootJump = 0f;
|
||||||
bool sawCliffFall = false;
|
bool sawCliffFall = false;
|
||||||
bool sawCliffLandingDip = false;
|
bool sawCliffLandingDip = false;
|
||||||
var view = world.View;
|
var view = world.View;
|
||||||
|
|
@ -1600,6 +1603,12 @@ namespace RustToDust.Tests
|
||||||
maxVelY = MathF.Max(maxVelY, vy);
|
maxVelY = MathF.Max(maxVelY, vy);
|
||||||
minVelY = MathF.Min(minVelY, vy);
|
minVelY = MathF.Min(minVelY, vy);
|
||||||
maxReachedY = MathF.Max(maxReachedY, view.PositionY[lane]);
|
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)
|
if (view.PositionZ[lane] > 56f && ws.IsAirborne)
|
||||||
{
|
{
|
||||||
|
|
@ -1613,11 +1622,12 @@ namespace RustToDust.Tests
|
||||||
|
|
||||||
_output.WriteLine(
|
_output.WriteLine(
|
||||||
$"{spec.Id,-10} curbs 0.30/0.45/0.60m + 3m cliff: endZ={view.PositionZ[lane]:F1}m maxY={maxReachedY:F2}m " +
|
$"{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(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(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(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(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");
|
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 footDelta = Vector3.Distance(sole, prevSoles[i]);
|
||||||
float maxAllowedDelta = (wasAirborne || ws.IsAirborne)
|
float maxAllowedDelta = (wasAirborne || ws.IsAirborne)
|
||||||
? 1.25f * MathF.Max(1f, ws.GeomScale)
|
? 1.25f * MathF.Max(1f, ws.GeomScale)
|
||||||
: MathF.Max(1.65f * ws.GeomScale, spec.MaxSpeed * ArenaSession.FixedDt * 4.2f);
|
: 1.65f * MathF.Max(1f, ws.GeomScale);
|
||||||
Assert.True(footDelta <= maxAllowedDelta,
|
Assert.True(footDelta < maxAllowedDelta,
|
||||||
$"{spec.Id} ({map}) tick {t} leg {i}: foot teleport delta {footDelta:F3}m > {maxAllowedDelta:F3}m");
|
$"{spec.Id} ({map}) tick {t} leg {i}: foot teleport delta {footDelta:F3}m >= {maxAllowedDelta:F3}m");
|
||||||
prevSoles[i] = sole;
|
prevSoles[i] = sole;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2008,50 +2018,85 @@ namespace RustToDust.Tests
|
||||||
Assert.True(dist3D <= reachLimit,
|
Assert.True(dist3D <= reachLimit,
|
||||||
$"{spec.Id} Sion steep slope tick {t} leg {i}: 3D reach overflow {dist3D:F3} > {reachLimit:F3}");
|
$"{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 footJump = Vector3.Distance(ws.FootSole[i], prevSoles[i]);
|
||||||
float maxJump = MathF.Max(1.65f * ws.GeomScale, spec.MaxSpeed * ArenaSession.FixedDt * 4.2f);
|
float maxJump = 1.65f * MathF.Max(1f, ws.GeomScale);
|
||||||
Assert.True(footJump <= maxJump,
|
Assert.True(footJump < maxJump,
|
||||||
$"{spec.Id} Sion steep slope tick {t} leg {i}: teleport jump {footJump:F3}m > {maxJump:F3}m");
|
$"{spec.Id} Sion steep slope tick {t} leg {i}: teleport jump {footJump:F3}m >= {maxJump:F3}m");
|
||||||
prevSoles[i] = ws.FootSole[i];
|
prevSoles[i] = ws.FootSole[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Kestrel sprinting straight uphill on steep Sion hill must stay grounded (no false blast launch from slopeVy)
|
// 2. Kestrel + Spectre + ExemplarFrame sprinting across Sion curbs/hills must stay grounded with zero non-blast launches & < 1.65m foot deltas
|
||||||
sionSession.SetContenderPose(0, steepSite.X, steepSite.Z, steepSite.Yaw);
|
foreach (var sprintSpec in new[] { Catalog.Kestrel, Catalog.Spectre, ExemplarFrame })
|
||||||
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++)
|
|
||||||
{
|
{
|
||||||
var (nx, ny, nz) = sionSession.State.Terrain.SampleNormal(kestrel.X, kestrel.Z);
|
bool isSteepTest = sprintSpec.Id == "kestrel";
|
||||||
float upYaw = (ny < 0.995f) ? MathF.Atan2(-nx, -nz) : steepSite.Yaw;
|
float startX = isSteepTest ? steepSite.X : 0f;
|
||||||
sionSession.SetHumanInput(0, new PlayerInput(
|
float startZ = isSteepTest ? steepSite.Z : -15f;
|
||||||
1.0f, 0f,
|
float startYaw = isSteepTest ? steepSite.Yaw : 0f;
|
||||||
kestrel.X + 40f * MathF.Sin(upYaw),
|
sionSession.SetContenderPose(0, startX, startZ, startYaw);
|
||||||
kestrel.Z + 40f * MathF.Cos(upYaw),
|
sionSession.State.SpawnChassisDrop(startX, startZ, sprintSpec);
|
||||||
false, false, false));
|
Assert.True(sionSession.TrySwapNearbyChassis(0));
|
||||||
sionSession.Step();
|
sionSession.SetContenderPose(0, startX, startZ, startYaw);
|
||||||
|
|
||||||
if (kWs.IsAirborne) airborneTicks++;
|
var contender = sionSession.State.Contenders[0];
|
||||||
maxVelY = MathF.Max(maxVelY, kView.VelocityY[kLane]);
|
var cBody = sionSession.GetContenderBody(contender.Id)!.Value;
|
||||||
float surfY = sionSession.State.Terrain.SampleHeight(kestrel.X, kestrel.Z);
|
var cWs = sionSession.GetWalkerState(true, contender.Id)!;
|
||||||
maxAboveGround = MathF.Max(maxAboveGround, kestrel.Y - (surfY + MatchRules.GetRideHeight(Catalog.Kestrel)));
|
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
|
// 3. Low upward splash impulse (< 3.5 m/s) must NOT be zeroed out on tick 1
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue