Cut 5b-2: Hybrid B centroidal GRF + 2nd-order joint mech locomotion across all 7 walkers
This commit is contained in:
parent
ce95580410
commit
dee2e738d8
9 changed files with 3077 additions and 431 deletions
|
|
@ -549,15 +549,29 @@ public partial class ArenaRenderer : Node3D
|
||||||
{
|
{
|
||||||
vis.RigDtAccum = 0f;
|
vis.RigDtAccum = 0f;
|
||||||
vis.RigSkipFrames = 0;
|
vis.RigSkipFrames = 0;
|
||||||
|
if (c.Grid.Spec.IsWalker && session.TrySampleInterpolatedWalkerPose(true, c.Id, alpha, out var walkerSnap))
|
||||||
|
{
|
||||||
|
VehicleRigAnimator.Update(vis.Visual, c, vel, vis.Visual.Root.Basis, dt, in walkerSnap);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
VehicleRigAnimator.Update(vis.Visual, c, vel, vis.Visual.Root.Basis, dt);
|
VehicleRigAnimator.Update(vis.Visual, c, vel, vis.Visual.Root.Basis, dt);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
vis.RigDtAccum += dt;
|
vis.RigDtAccum += dt;
|
||||||
vis.RigSkipFrames++;
|
vis.RigSkipFrames++;
|
||||||
if (vis.RigSkipFrames >= 2)
|
if (vis.RigSkipFrames >= 2)
|
||||||
|
{
|
||||||
|
if (c.Grid.Spec.IsWalker && session.TrySampleInterpolatedWalkerPose(true, c.Id, alpha, out var walkerSnap))
|
||||||
|
{
|
||||||
|
VehicleRigAnimator.Update(vis.Visual, c, vel, vis.Visual.Root.Basis, vis.RigDtAccum, in walkerSnap);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
VehicleRigAnimator.Update(vis.Visual, c, vel, vis.Visual.Root.Basis, vis.RigDtAccum);
|
VehicleRigAnimator.Update(vis.Visual, c, vel, vis.Visual.Root.Basis, vis.RigDtAccum);
|
||||||
|
}
|
||||||
vis.RigDtAccum = 0f;
|
vis.RigDtAccum = 0f;
|
||||||
vis.RigSkipFrames = 0;
|
vis.RigSkipFrames = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -668,8 +682,15 @@ public partial class ArenaRenderer : Node3D
|
||||||
IsGrounded: !s.Grid.Spec.IsVtol);
|
IsGrounded: !s.Grid.Spec.IsVtol);
|
||||||
|
|
||||||
vis.Visual.SyncMountedGear(s.Grid);
|
vis.Visual.SyncMountedGear(s.Grid);
|
||||||
|
if (s.Grid.Spec.IsWalker && session.TrySampleInterpolatedWalkerPose(false, s.Id, alpha, out var walkerSnap))
|
||||||
|
{
|
||||||
|
VehicleRigAnimator.Update(vis.Visual, in rigInput, vis.Visual.Root.Basis, in walkerSnap);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
VehicleRigAnimator.Update(vis.Visual, in rigInput, vis.Visual.Root.Basis);
|
VehicleRigAnimator.Update(vis.Visual, in rigInput, vis.Visual.Root.Basis);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
vis.Visual.SubmitToPool(_partPool);
|
vis.Visual.SubmitToPool(_partPool);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -567,20 +567,25 @@ public sealed class VehicleAssetCache : IDisposable
|
||||||
|
|
||||||
private static readonly HashSet<string> ExactStructuralNodeNames = new(StringComparer.OrdinalIgnoreCase)
|
private static readonly HashSet<string> ExactStructuralNodeNames = new(StringComparer.OrdinalIgnoreCase)
|
||||||
{
|
{
|
||||||
"chassis", "hull", "pelvis", "core", "trunk", "waist", "torso.pose", "aim.turret", "hull.pose",
|
"chassis", "hull", "pelvis", "core", "trunk", "waist", "waistlug", "torso.pose", "aim.turret", "hull.pose",
|
||||||
"legl.hip", "legr.hip", "legl.shin", "legr.shin", "legl.foot", "legr.foot",
|
"legl.hipslew", "legr.hipslew", "legl.hip", "legr.hip", "legl.hipyaw", "legr.hipyaw",
|
||||||
|
"legl.cross", "legr.cross",
|
||||||
|
"legl.shin", "legr.shin", "legl.foot", "legr.foot", "footl", "footr",
|
||||||
"legl.upper", "legr.upper", "legl.lower", "legr.lower", "legl.ankle", "legr.ankle",
|
"legl.upper", "legr.upper", "legl.lower", "legr.lower", "legl.ankle", "legr.ankle",
|
||||||
"legl.thigh", "legr.thigh", "legl.cannon", "legr.cannon",
|
"legl.thigh", "legr.thigh", "legl.cannon", "legr.cannon",
|
||||||
"legl.oleo", "legr.oleo", "legl.oleofork", "legr.oleofork",
|
"legl.oleo", "legr.oleo", "legl.oleofork", "legr.oleofork",
|
||||||
"legl.torqueup", "legr.torqueup", "legl.torquelow", "legr.torquelow",
|
"legl.torqueup", "legr.torqueup", "legl.torquelow", "legr.torquelow",
|
||||||
"legl.lug", "legr.lug", "legl.ramluga0", "legl.ramluga1", "legr.ramluga0", "legr.ramluga1",
|
"legl.lug", "legr.lug", "legl.ramluga0", "legl.ramluga1", "legr.ramluga0", "legr.ramluga1",
|
||||||
"legl.recessram0", "legl.recessram1", "legr.recessram0", "legr.recessram1",
|
"legl.recessram0", "legl.recessram1", "legr.recessram0", "legr.recessram1",
|
||||||
|
"legfl.coxa", "legfr.coxa", "legbl.coxa", "legbr.coxa",
|
||||||
"legfl.s1", "legfr.s1", "legbl.s1", "legbr.s1",
|
"legfl.s1", "legfr.s1", "legbl.s1", "legbr.s1",
|
||||||
"legfl.s2", "legfr.s2", "legbl.s2", "legbr.s2",
|
"legfl.s2", "legfr.s2", "legbl.s2", "legbr.s2",
|
||||||
"footfl", "footfr", "footbl", "footbr",
|
"footfl", "footfr", "footbl", "footbr",
|
||||||
|
"bone.hip_splay.fl", "bone.hip_splay.fr", "bone.hip_splay.rl", "bone.hip_splay.rr",
|
||||||
"thigh.fl", "thigh.fr", "thigh.rl", "thigh.rr",
|
"thigh.fl", "thigh.fr", "thigh.rl", "thigh.rr",
|
||||||
"shin.fl", "shin.fr", "shin.rl", "shin.rr",
|
"shin.fl", "shin.fr", "shin.rl", "shin.rr",
|
||||||
"ankle.fl", "ankle.fr", "ankle.rl", "ankle.rr"
|
"ankle.fl", "ankle.fr", "ankle.rl", "ankle.rr",
|
||||||
|
"foot.fl", "foot.fr", "foot.rl", "foot.rr"
|
||||||
};
|
};
|
||||||
|
|
||||||
private static bool IsStructuralNodeName(string name) =>
|
private static bool IsStructuralNodeName(string name) =>
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Godot;
|
using Godot;
|
||||||
using RustToDust.Core;
|
using RustToDust.Core;
|
||||||
|
using RustToDust.Ymir;
|
||||||
|
|
||||||
namespace RustToDust.Client;
|
namespace RustToDust.Client;
|
||||||
|
|
||||||
|
|
@ -23,8 +24,9 @@ public readonly record struct VehicleRigDriveInput(
|
||||||
/// - Wheeled: wheel spin (<c>v / r</c>), front-axle steering, subtle chassis suspension roll/pitch.
|
/// - Wheeled: wheel spin (<c>v / r</c>), front-axle steering, subtle chassis suspension roll/pitch.
|
||||||
/// - Turrets/Torsos/Arms: yaw tracking (<c>joint.turret_yaw</c>, <c>joint.torso_yaw</c>) & arm pitch.
|
/// - Turrets/Torsos/Arms: yaw tracking (<c>joint.turret_yaw</c>, <c>joint.torso_yaw</c>) & arm pitch.
|
||||||
/// - VTOL: rotor spin scaled by <c>EngineThermalPerf</c> + lift demand, nacelle tilt with acceleration.
|
/// - VTOL: rotor spin scaled by <c>EngineThermalPerf</c> + lift demand, nacelle tilt with acceleration.
|
||||||
/// - Walkers/Mechs: procedural leg stride returning to neutral rest when stopped, Manticore tail aiming,
|
/// - Walkers/Mechs: pure FK posing from Hybrid B <see cref="WalkerVisualSnapshot"/> with per-segment
|
||||||
/// and Breaker's damped oleo strut + 2-link scissor torque links + telescoping recess rams.
|
/// rest-basis alignment (<c>Q_offset</c>), Manticore tail aiming, and Breaker's real GRF-driven
|
||||||
|
/// oleo strut + 2-link scissor torque links + telescoping recess rams.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class VehicleRigAnimator
|
public static class VehicleRigAnimator
|
||||||
{
|
{
|
||||||
|
|
@ -73,10 +75,27 @@ public static class VehicleRigAnimator
|
||||||
public readonly List<RamBinding> Rams = new();
|
public readonly List<RamBinding> Rams = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class WalkerFootSample
|
public sealed class SegmentBinding
|
||||||
{
|
{
|
||||||
public required Node3D[] ChainFromModelRoot;
|
public required Node3D Node;
|
||||||
public required Vector3[] LocalPoints;
|
public required Transform3D RestLocal;
|
||||||
|
public required Node3D[] IntermediateBefore;
|
||||||
|
public required Basis QOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class WalkerLegBinding
|
||||||
|
{
|
||||||
|
public SegmentBinding? Coxa;
|
||||||
|
public required SegmentBinding Thigh;
|
||||||
|
public required SegmentBinding Shin;
|
||||||
|
public SegmentBinding? Cannon;
|
||||||
|
public required SegmentBinding Foot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class WalkerVisualRig
|
||||||
|
{
|
||||||
|
public required WalkerGeometrySpec Geom;
|
||||||
|
public required WalkerLegBinding[] Legs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class RigState
|
public sealed class RigState
|
||||||
|
|
@ -87,15 +106,12 @@ public static class VehicleRigAnimator
|
||||||
public float ArmPitchRad;
|
public float ArmPitchRad;
|
||||||
public float RotorSpinRad;
|
public float RotorSpinRad;
|
||||||
public float NacelleTiltRad;
|
public float NacelleTiltRad;
|
||||||
public float StridePhaseRad;
|
|
||||||
public float StrideAmp;
|
|
||||||
public float PrevForwardSpeed;
|
public float PrevForwardSpeed;
|
||||||
public float PrevVelY;
|
|
||||||
public float ChassisPitchRad;
|
public float ChassisPitchRad;
|
||||||
public float ChassisRollRad;
|
public float ChassisRollRad;
|
||||||
public float ElapsedSeconds;
|
public float ElapsedSeconds;
|
||||||
public BreakerMechRig? BreakerRig;
|
public BreakerMechRig? BreakerRig;
|
||||||
public List<WalkerFootSample>? FootSamples;
|
public WalkerVisualRig? WalkerRig;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Update(
|
public static void Update(
|
||||||
|
|
@ -105,6 +121,25 @@ public static class VehicleRigAnimator
|
||||||
Basis worldBasis,
|
Basis worldBasis,
|
||||||
float dt,
|
float dt,
|
||||||
bool snap = false)
|
bool snap = false)
|
||||||
|
{
|
||||||
|
var input = BuildContenderInput(c, velocity, dt);
|
||||||
|
Update(visual, in input, worldBasis, snap);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Update(
|
||||||
|
VehicleVisualInstance visual,
|
||||||
|
ContenderState c,
|
||||||
|
Vector3 velocity,
|
||||||
|
Basis worldBasis,
|
||||||
|
float dt,
|
||||||
|
in WalkerVisualSnapshot walkerSnap,
|
||||||
|
bool snap = false)
|
||||||
|
{
|
||||||
|
var input = BuildContenderInput(c, velocity, dt);
|
||||||
|
Update(visual, in input, worldBasis, in walkerSnap, snap);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static VehicleRigDriveInput BuildContenderInput(ContenderState c, Vector3 velocity, float dt)
|
||||||
{
|
{
|
||||||
float aimYawWorld = c.Yaw;
|
float aimYawWorld = c.Yaw;
|
||||||
float dx = c.AimX - c.X;
|
float dx = c.AimX - c.X;
|
||||||
|
|
@ -125,7 +160,7 @@ public static class VehicleRigAnimator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var input = new VehicleRigDriveInput(
|
return new VehicleRigDriveInput(
|
||||||
Velocity: velocity,
|
Velocity: velocity,
|
||||||
Yaw: c.Yaw,
|
Yaw: c.Yaw,
|
||||||
AimYawWorld: aimYawWorld,
|
AimYawWorld: aimYawWorld,
|
||||||
|
|
@ -136,8 +171,6 @@ public static class VehicleRigAnimator
|
||||||
EngineThermalPerf: c.Grid.ComputeEngineThermalPerformance(),
|
EngineThermalPerf: c.Grid.ComputeEngineThermalPerformance(),
|
||||||
DeltaTime: dt,
|
DeltaTime: dt,
|
||||||
IsGrounded: !c.Grid.Spec.IsVtol);
|
IsGrounded: !c.Grid.Spec.IsVtol);
|
||||||
|
|
||||||
Update(visual, in input, worldBasis, snap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Update(
|
public static void Update(
|
||||||
|
|
@ -145,6 +178,29 @@ public static class VehicleRigAnimator
|
||||||
in VehicleRigDriveInput input,
|
in VehicleRigDriveInput input,
|
||||||
Basis worldBasis,
|
Basis worldBasis,
|
||||||
bool snap = false)
|
bool snap = false)
|
||||||
|
{
|
||||||
|
UpdateCore(visual, in input, worldBasis, hasWalkerSnap: false, in DefaultSnapshot, snap);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Update(
|
||||||
|
VehicleVisualInstance visual,
|
||||||
|
in VehicleRigDriveInput input,
|
||||||
|
Basis worldBasis,
|
||||||
|
in WalkerVisualSnapshot walkerSnap,
|
||||||
|
bool snap = false)
|
||||||
|
{
|
||||||
|
UpdateCore(visual, in input, worldBasis, hasWalkerSnap: true, in walkerSnap, snap);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly WalkerVisualSnapshot DefaultSnapshot = default;
|
||||||
|
|
||||||
|
private static void UpdateCore(
|
||||||
|
VehicleVisualInstance visual,
|
||||||
|
in VehicleRigDriveInput input,
|
||||||
|
Basis worldBasis,
|
||||||
|
bool hasWalkerSnap,
|
||||||
|
in WalkerVisualSnapshot walkerSnap,
|
||||||
|
bool snap)
|
||||||
{
|
{
|
||||||
float dt = Sanitize(input.DeltaTime, 0f, 0f, 0.1f);
|
float dt = Sanitize(input.DeltaTime, 0f, 0f, 0.1f);
|
||||||
if (!snap && dt <= 0f)
|
if (!snap && dt <= 0f)
|
||||||
|
|
@ -170,7 +226,6 @@ public static class VehicleRigAnimator
|
||||||
|
|
||||||
float forwardSpeed = vel.Dot(fwd);
|
float forwardSpeed = vel.Dot(fwd);
|
||||||
float lateralSpeed = vel.Dot(right);
|
float lateralSpeed = vel.Dot(right);
|
||||||
float horizSpeed = MathF.Sqrt(forwardSpeed * forwardSpeed + lateralSpeed * lateralSpeed);
|
|
||||||
|
|
||||||
float relYaw = MatchRules.NormalizeAngle(aimYawWorld - yaw);
|
float relYaw = MatchRules.NormalizeAngle(aimYawWorld - yaw);
|
||||||
float aimPitchRad = Mathf.DegToRad(aimPitchDeg);
|
float aimPitchRad = Mathf.DegToRad(aimPitchDeg);
|
||||||
|
|
@ -194,7 +249,14 @@ public static class VehicleRigAnimator
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MobilityKind.Walker:
|
case MobilityKind.Walker:
|
||||||
UpdateWalker(visual, st, horizSpeed, forwardSpeed, vel.Y, steerCmd, relYaw, aimPitchRad, dt, blendMed);
|
if (hasWalkerSnap)
|
||||||
|
{
|
||||||
|
UpdateWalkerFromSnapshot(visual, st, in walkerSnap, relYaw, aimPitchRad, dt, blendMed);
|
||||||
|
}
|
||||||
|
else if (string.Equals(visual.ModelId, "manticore", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
AnimateManticoreTail(visual, st, relYaw, aimPitchRad, blendMed);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MobilityKind.Tracked:
|
case MobilityKind.Tracked:
|
||||||
|
|
@ -203,7 +265,6 @@ public static class VehicleRigAnimator
|
||||||
}
|
}
|
||||||
|
|
||||||
st.PrevForwardSpeed = forwardSpeed;
|
st.PrevForwardSpeed = forwardSpeed;
|
||||||
st.PrevVelY = vel.Y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void UpdateTurretAndTorso(
|
private static void UpdateTurretAndTorso(
|
||||||
|
|
@ -257,7 +318,6 @@ public static class VehicleRigAnimator
|
||||||
float dt,
|
float dt,
|
||||||
float blend)
|
float blend)
|
||||||
{
|
{
|
||||||
// Determine average wheel radius from wheel joint Y height in grounded GLB
|
|
||||||
float radiusSum = 0f;
|
float radiusSum = 0f;
|
||||||
int radiusCount = 0;
|
int radiusCount = 0;
|
||||||
foreach (var (jid, j) in visual.Joints)
|
foreach (var (jid, j) in visual.Joints)
|
||||||
|
|
@ -296,7 +356,6 @@ public static class VehicleRigAnimator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subtle chassis suspension pitch & roll
|
|
||||||
float accel = dt > 1e-4f ? (forwardSpeed - st.PrevForwardSpeed) / dt : 0f;
|
float accel = dt > 1e-4f ? (forwardSpeed - st.PrevForwardSpeed) / dt : 0f;
|
||||||
float targetPitch = Math.Clamp(-accel * 0.0022f, -0.05f, 0.05f);
|
float targetPitch = Math.Clamp(-accel * 0.0022f, -0.05f, 0.05f);
|
||||||
float targetRoll = Math.Clamp(lateralSpeed * 0.0045f + steerCmd * MathF.Min(1f, MathF.Abs(forwardSpeed) / 14f) * 0.035f, -0.06f, 0.06f);
|
float targetRoll = Math.Clamp(lateralSpeed * 0.0045f + steerCmd * MathF.Min(1f, MathF.Abs(forwardSpeed) / 14f) * 0.035f, -0.06f, 0.06f);
|
||||||
|
|
@ -366,196 +425,348 @@ public static class VehicleRigAnimator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void UpdateWalker(
|
private static void UpdateWalkerFromSnapshot(
|
||||||
VehicleVisualInstance visual,
|
VehicleVisualInstance visual,
|
||||||
RigState st,
|
RigState st,
|
||||||
float horizSpeed,
|
in WalkerVisualSnapshot snap,
|
||||||
float forwardSpeed,
|
|
||||||
float velY,
|
|
||||||
float steerCmd,
|
|
||||||
float relYaw,
|
float relYaw,
|
||||||
float aimPitchRad,
|
float aimPitchRad,
|
||||||
float dt,
|
float dt,
|
||||||
float blend)
|
float blend)
|
||||||
{
|
{
|
||||||
EnsureWalkerFootSamples(visual, st);
|
var rig = st.WalkerRig ??= InitWalkerRig(visual);
|
||||||
|
if (rig is null)
|
||||||
float targetAmp = Math.Clamp(horizSpeed / 6.5f + MathF.Abs(steerCmd) * 0.32f, 0f, 1f);
|
|
||||||
st.StrideAmp += (targetAmp - st.StrideAmp) * blend;
|
|
||||||
|
|
||||||
float strideDir = forwardSpeed >= -0.35f ? 1f : -1f;
|
|
||||||
float phaseRate = (2.8f + horizSpeed * 0.48f + MathF.Abs(steerCmd) * 1.4f) * strideDir;
|
|
||||||
st.StridePhaseRad = MathF.IEEERemainder(st.StridePhaseRad + phaseRate * dt, MathF.Tau);
|
|
||||||
|
|
||||||
float phiL = st.StridePhaseRad;
|
|
||||||
float phiR = st.StridePhaseRad + MathF.PI;
|
|
||||||
string id = visual.ModelId.ToLowerInvariant();
|
|
||||||
|
|
||||||
switch (id)
|
|
||||||
{
|
|
||||||
case "breaker":
|
|
||||||
AnimateBipedLeg(visual, "LegL.Hip", "LegL.Shin", "LegL.Foot", phiL, st.StrideAmp, signX: -1f);
|
|
||||||
AnimateBipedLeg(visual, "LegR.Hip", "LegR.Shin", "LegR.Foot", phiR, st.StrideAmp, signX: -1f);
|
|
||||||
ApplyPelvisBob(visual, "Pelvis", st.StridePhaseRad, st.StrideAmp, bobScale: 0.06f, rollScale: 0.024f);
|
|
||||||
StepBreakerMechanisms(visual, st, phiL, phiR, velY, dt);
|
|
||||||
ApplyWalkerFloorClearance(visual, st, "Pelvis");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "paladin":
|
|
||||||
AnimateBipedVehicleX(visual, "LegL.Upper", "LegL.Lower", "LegL.Ankle", phiL, st.StrideAmp, hipAmp: 0.22f, kneeLiftAmp: 0.28f, kneeForwardFlexAmp: 0.08f);
|
|
||||||
AnimateBipedVehicleX(visual, "LegR.Upper", "LegR.Lower", "LegR.Ankle", phiR, st.StrideAmp, hipAmp: 0.22f, kneeLiftAmp: 0.28f, kneeForwardFlexAmp: 0.08f);
|
|
||||||
ApplyPelvisBob(visual, "Pelvis", st.StridePhaseRad, st.StrideAmp, bobScale: 0.07f, rollScale: 0.020f);
|
|
||||||
ApplyWalkerFloorClearance(visual, st, "Pelvis");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "raptor":
|
|
||||||
AnimateBipedVehicleX(visual, "LegL.Thigh", "LegL.Shin", "LegL.Cannon", phiL, st.StrideAmp, hipAmp: 0.20f, kneeLiftAmp: 0.34f, kneeForwardFlexAmp: 0.22f);
|
|
||||||
AnimateBipedVehicleX(visual, "LegR.Thigh", "LegR.Shin", "LegR.Cannon", phiR, st.StrideAmp, hipAmp: 0.20f, kneeLiftAmp: 0.34f, kneeForwardFlexAmp: 0.22f);
|
|
||||||
ApplyPelvisBob(visual, "Pelvis", st.StridePhaseRad, st.StrideAmp, bobScale: 0.06f, rollScale: 0.020f);
|
|
||||||
ApplyWalkerFloorClearance(visual, st, "Pelvis");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "spectre":
|
|
||||||
AnimateBipedVehicleX(visual, "LegL.Thigh", "LegL.Shin", "LegL.Cannon", phiL, st.StrideAmp, hipAmp: 0.22f, kneeLiftAmp: 0.32f, kneeForwardFlexAmp: 0f);
|
|
||||||
AnimateBipedVehicleX(visual, "LegR.Thigh", "LegR.Shin", "LegR.Cannon", phiR, st.StrideAmp, hipAmp: 0.22f, kneeLiftAmp: 0.32f, kneeForwardFlexAmp: 0f);
|
|
||||||
ApplyPelvisBob(visual, "Pelvis", st.StridePhaseRad, st.StrideAmp, bobScale: 0.06f, rollScale: 0.020f);
|
|
||||||
ApplyWalkerFloorClearance(visual, st, "Pelvis");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "kestrel":
|
|
||||||
// Kestrel leg meshes are baked under Pelvis; animate Pelvis stride bob/sway with floor clearance
|
|
||||||
ApplyPelvisBob(visual, "Pelvis", st.StridePhaseRad, st.StrideAmp, bobScale: 0.07f, rollScale: 0.024f);
|
|
||||||
ApplyWalkerFloorClearance(visual, st, "Pelvis");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "manticore":
|
|
||||||
AnimateManticoreLeg(visual, "LegFL.S1", "LegFL.S2", "FootFL", phiL, st.StrideAmp, isFront: true);
|
|
||||||
AnimateManticoreLeg(visual, "LegBR.S1", "LegBR.S2", "FootBR", phiL, st.StrideAmp, isFront: false);
|
|
||||||
AnimateManticoreLeg(visual, "LegFR.S1", "LegFR.S2", "FootFR", phiR, st.StrideAmp, isFront: true);
|
|
||||||
AnimateManticoreLeg(visual, "LegBL.S1", "LegBL.S2", "FootBL", phiR, st.StrideAmp, isFront: false);
|
|
||||||
ApplyPelvisBob(visual, "Hull", st.StridePhaseRad, st.StrideAmp, bobScale: 0.04f, rollScale: 0.018f);
|
|
||||||
ApplyWalkerFloorClearance(visual, st, "Hull");
|
|
||||||
AnimateManticoreTail(visual, st, relYaw, aimPitchRad, blend);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "bastion":
|
|
||||||
AnimateBastionLeg(visual, "Thigh.fl", "Shin.fl", "Ankle.fl", phiL, st.StrideAmp, isFront: true);
|
|
||||||
AnimateBastionLeg(visual, "Thigh.rr", "Shin.rr", "Ankle.rr", phiL, st.StrideAmp, isFront: false);
|
|
||||||
AnimateBastionLeg(visual, "Thigh.fr", "Shin.fr", "Ankle.fr", phiR, st.StrideAmp, isFront: true);
|
|
||||||
AnimateBastionLeg(visual, "Thigh.rl", "Shin.rl", "Ankle.rl", phiR, st.StrideAmp, isFront: false);
|
|
||||||
ApplyPelvisBob(visual, "Trunk", st.StridePhaseRad, st.StrideAmp, bobScale: 0.05f, rollScale: 0.012f);
|
|
||||||
ApplyWalkerFloorClearance(visual, st, "Trunk");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static float SwingLift(float phase) => MathF.Max(0f, MathF.Cos(phase));
|
|
||||||
|
|
||||||
private static void AnimateBipedLeg(
|
|
||||||
VehicleVisualInstance visual,
|
|
||||||
string hipName,
|
|
||||||
string shinName,
|
|
||||||
string footName,
|
|
||||||
float phase,
|
|
||||||
float amp,
|
|
||||||
float signX)
|
|
||||||
{
|
|
||||||
float hipAng = MathF.Sin(phase) * 0.30f * amp;
|
|
||||||
float kneeAng = MathF.Max(0f, -MathF.Cos(phase)) * 0.38f * amp;
|
|
||||||
float footAng = -(hipAng * 0.55f + kneeAng * 0.45f);
|
|
||||||
|
|
||||||
RotateVehicleAxis(visual, hipName, Vector3.Right, hipAng * signX);
|
|
||||||
RotateVehicleAxis(visual, shinName, Vector3.Right, kneeAng * signX);
|
|
||||||
RotateVehicleAxis(visual, footName, Vector3.Right, footAng * signX);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void AnimateBipedVehicleX(
|
|
||||||
VehicleVisualInstance visual,
|
|
||||||
string thighName,
|
|
||||||
string shinName,
|
|
||||||
string footName,
|
|
||||||
float phase,
|
|
||||||
float amp,
|
|
||||||
float hipAmp,
|
|
||||||
float kneeLiftAmp,
|
|
||||||
float kneeForwardFlexAmp)
|
|
||||||
{
|
|
||||||
float hipAng = -MathF.Sin(phase) * hipAmp * amp;
|
|
||||||
float kneeAng = (SwingLift(phase) * kneeLiftAmp + MathF.Max(0f, MathF.Sin(phase)) * kneeForwardFlexAmp) * amp;
|
|
||||||
float footAng = -(hipAng + kneeAng);
|
|
||||||
|
|
||||||
RotateVehicleAxis(visual, thighName, Vector3.Right, hipAng);
|
|
||||||
RotateVehicleAxis(visual, shinName, Vector3.Right, kneeAng);
|
|
||||||
RotateVehicleAxis(visual, footName, Vector3.Right, footAng);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void AnimateManticoreLeg(
|
|
||||||
VehicleVisualInstance visual,
|
|
||||||
string s1Name,
|
|
||||||
string s2Name,
|
|
||||||
string footName,
|
|
||||||
float phase,
|
|
||||||
float amp,
|
|
||||||
bool isFront)
|
|
||||||
{
|
|
||||||
float s2Ang = -MathF.Sin(phase) * 0.22f * amp;
|
|
||||||
float liftSign = isFront ? -1f : 1f;
|
|
||||||
float s1Ang = SwingLift(phase) * 0.26f * amp * liftSign;
|
|
||||||
float footAng = -(s1Ang + s2Ang);
|
|
||||||
|
|
||||||
RotateVehicleAxis(visual, s1Name, Vector3.Right, s1Ang);
|
|
||||||
RotateVehicleAxis(visual, s2Name, Vector3.Right, s2Ang);
|
|
||||||
RotateVehicleAxis(visual, footName, Vector3.Right, footAng);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void AnimateBastionLeg(
|
|
||||||
VehicleVisualInstance visual,
|
|
||||||
string thighName,
|
|
||||||
string shinName,
|
|
||||||
string ankleName,
|
|
||||||
float phase,
|
|
||||||
float amp,
|
|
||||||
bool isFront)
|
|
||||||
{
|
|
||||||
float thAng;
|
|
||||||
float shAng;
|
|
||||||
if (isFront)
|
|
||||||
{
|
|
||||||
thAng = -MathF.Sin(phase) * 0.16f * amp;
|
|
||||||
shAng = SwingLift(phase) * 0.14f * amp;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
thAng = (MathF.Max(0f, -MathF.Sin(phase)) * 0.14f + SwingLift(phase) * 0.10f) * amp;
|
|
||||||
shAng = (-MathF.Sin(phase) * 0.16f - SwingLift(phase) * 0.16f) * amp;
|
|
||||||
}
|
|
||||||
float anAng = -(thAng + shAng);
|
|
||||||
|
|
||||||
RotateVehicleAxis(visual, thighName, Vector3.Right, thAng);
|
|
||||||
RotateVehicleAxis(visual, shinName, Vector3.Right, shAng);
|
|
||||||
RotateVehicleAxis(visual, ankleName, Vector3.Right, anAng);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void ApplyPelvisBob(
|
|
||||||
VehicleVisualInstance visual,
|
|
||||||
string rootNodeName,
|
|
||||||
float phase,
|
|
||||||
float amp,
|
|
||||||
float bobScale,
|
|
||||||
float rollScale = 0.024f)
|
|
||||||
{
|
|
||||||
if (visual.GetNamedNode(rootNodeName) is not { } node ||
|
|
||||||
!visual.TryGetRestLocal(rootNodeName, out var rest))
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
float bobY = MathF.Abs(MathF.Sin(phase)) * bobScale * amp;
|
var geom = rig.Geom;
|
||||||
float swayRoll = MathF.Cos(phase) * rollScale * amp;
|
var bodyRotSys = snap.ComRot.LengthSquared() < 1e-6f
|
||||||
Basis roll = new Basis(Vector3.Back, swayRoll);
|
? System.Numerics.Quaternion.Identity
|
||||||
node.Transform = new Transform3D(roll * rest.Basis, rest.Origin + new Vector3(0f, bobY, 0f));
|
: System.Numerics.Quaternion.Normalize(snap.ComRot);
|
||||||
|
var bodyRotInv = System.Numerics.Quaternion.Conjugate(bodyRotSys);
|
||||||
|
|
||||||
|
int count = Math.Min(rig.Legs.Length, snap.LegCount);
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
var legRig = rig.Legs[i];
|
||||||
|
var legSpec = geom.Legs[i];
|
||||||
|
var ang = snap.LegAngles[i];
|
||||||
|
if (!float.IsFinite(ang.HipPitch) || !float.IsFinite(ang.HipRoll) ||
|
||||||
|
!float.IsFinite(ang.KneeFlex) || !float.IsFinite(ang.HockFlex) ||
|
||||||
|
!float.IsFinite(ang.AnklePitch))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector3 footNormModel = ToGodot(System.Numerics.Vector3.Transform(snap.FootNormal[i], bodyRotInv));
|
||||||
|
footNormModel = footNormModel.LengthSquared() > 1e-6f ? footNormModel.Normalized() : Vector3.Up;
|
||||||
|
|
||||||
|
Vector3 r0 = ToGodot(legSpec.LegRight0);
|
||||||
|
Vector3 f0 = ToGodot(legSpec.LegFwd0);
|
||||||
|
|
||||||
|
Basis curModelBasis = Basis.Identity;
|
||||||
|
|
||||||
|
if (snap.IsArachnidUp)
|
||||||
|
{
|
||||||
|
float coxaYaw = ang.HipRoll;
|
||||||
|
Vector3 legOut = (f0 * MathF.Cos(coxaYaw) + r0 * MathF.Sin(coxaYaw)).Normalized();
|
||||||
|
Vector3 legRight = (r0 * MathF.Cos(coxaYaw) - f0 * MathF.Sin(coxaYaw)).Normalized();
|
||||||
|
|
||||||
|
if (legRig.Coxa is { } coxaSeg)
|
||||||
|
{
|
||||||
|
Basis coxaBasis = BasisFromDownAndRight(-legOut, Vector3.Up.Cross(legOut)) * coxaSeg.QOffset;
|
||||||
|
curModelBasis = ApplySegmentModelBasis(coxaSeg, curModelBasis, coxaBasis);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 s1Dir = (legOut * MathF.Cos(ang.HipPitch) + Vector3.Up * MathF.Sin(ang.HipPitch)).Normalized();
|
||||||
|
float s2Elev = ang.HipPitch - ang.KneeFlex;
|
||||||
|
Vector3 s2Dir = (legOut * MathF.Cos(s2Elev) + Vector3.Up * MathF.Sin(s2Elev)).Normalized();
|
||||||
|
|
||||||
|
Basis thighBasis = BasisFromDownAndRight(s1Dir, legRight) * legRig.Thigh.QOffset;
|
||||||
|
curModelBasis = ApplySegmentModelBasis(legRig.Thigh, curModelBasis, thighBasis);
|
||||||
|
|
||||||
|
Basis shinBasis = BasisFromDownAndRight(s2Dir, legRight) * legRig.Shin.QOffset;
|
||||||
|
curModelBasis = ApplySegmentModelBasis(legRig.Shin, curModelBasis, shinBasis);
|
||||||
|
|
||||||
|
float lat = Math.Clamp(footNormModel.Dot(legRight), -0.85f, 0.85f);
|
||||||
|
float planarMag = MathF.Sqrt(MathF.Max(0.01f, 1f - lat * lat));
|
||||||
|
Vector3 footUp = (legRight * lat + (Vector3.Up * MathF.Cos(ang.AnklePitch) + legOut * MathF.Sin(ang.AnklePitch)) * planarMag).Normalized();
|
||||||
|
Basis footBasis = BasisFromDownAndRight(-footUp, legRight) * legRig.Foot.QOffset;
|
||||||
|
ApplySegmentModelBasis(legRig.Foot, curModelBasis, footBasis);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float hipRoll = ang.HipRoll;
|
||||||
|
Vector3 legRight = (r0 * MathF.Cos(hipRoll) + Vector3.Up * MathF.Sin(hipRoll)).Normalized();
|
||||||
|
Vector3 downTilted = (-Vector3.Up * MathF.Cos(hipRoll) + r0 * MathF.Sin(hipRoll)).Normalized();
|
||||||
|
|
||||||
|
Vector3 thighDir = (downTilted * MathF.Cos(ang.HipPitch) + f0 * MathF.Sin(ang.HipPitch)).Normalized();
|
||||||
|
float shinAngle = ang.HipPitch - ang.KneeFlex;
|
||||||
|
Vector3 shinDir = (downTilted * MathF.Cos(shinAngle) + f0 * MathF.Sin(shinAngle)).Normalized();
|
||||||
|
|
||||||
|
Basis thighBasis = BasisFromDownAndRight(thighDir, legRight) * legRig.Thigh.QOffset;
|
||||||
|
curModelBasis = ApplySegmentModelBasis(legRig.Thigh, curModelBasis, thighBasis);
|
||||||
|
|
||||||
|
Basis shinBasis = BasisFromDownAndRight(shinDir, legRight) * legRig.Shin.QOffset;
|
||||||
|
curModelBasis = ApplySegmentModelBasis(legRig.Shin, curModelBasis, shinBasis);
|
||||||
|
|
||||||
|
if (snap.IsDigitigrade && legRig.Cannon is { } cannonSeg)
|
||||||
|
{
|
||||||
|
float cannonAngle = shinAngle + ang.HockFlex;
|
||||||
|
Vector3 cannonDir = (downTilted * MathF.Cos(cannonAngle) + f0 * MathF.Sin(cannonAngle)).Normalized();
|
||||||
|
Basis cannonBasis = BasisFromDownAndRight(cannonDir, legRight) * cannonSeg.QOffset;
|
||||||
|
curModelBasis = ApplySegmentModelBasis(cannonSeg, curModelBasis, cannonBasis);
|
||||||
|
}
|
||||||
|
|
||||||
|
float lat = Math.Clamp(footNormModel.Dot(legRight), -0.85f, 0.85f);
|
||||||
|
float planarMag = MathF.Sqrt(MathF.Max(0.01f, 1f - lat * lat));
|
||||||
|
Vector3 footUp = (legRight * lat + (Vector3.Up * MathF.Cos(ang.AnklePitch) + f0 * MathF.Sin(ang.AnklePitch)) * planarMag).Normalized();
|
||||||
|
Basis footBasis = BasisFromDownAndRight(-footUp, legRight) * legRig.Foot.QOffset;
|
||||||
|
ApplySegmentModelBasis(legRig.Foot, curModelBasis, footBasis);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string id = visual.ModelId;
|
||||||
|
if (string.Equals(id, "manticore", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
AnimateManticoreTail(visual, st, relYaw, aimPitchRad, blend);
|
||||||
|
}
|
||||||
|
else if (string.Equals(id, "breaker", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
StepBreakerLinkages(visual, snap.LoadG[0], snap.LoadG[1], dt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Basis ApplySegmentModelBasis(SegmentBinding seg, Basis curBasisInModel, Basis targetBasisInModel)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < seg.IntermediateBefore.Length; i++)
|
||||||
|
{
|
||||||
|
curBasisInModel *= seg.IntermediateBefore[i].Transform.Basis.Orthonormalized();
|
||||||
|
}
|
||||||
|
Basis localBasis = curBasisInModel.Inverse() * targetBasisInModel;
|
||||||
|
seg.Node.Transform = new Transform3D(localBasis, seg.RestLocal.Origin);
|
||||||
|
return targetBasisInModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static WalkerVisualRig? InitWalkerRig(VehicleVisualInstance visual)
|
||||||
|
{
|
||||||
|
var geom = WalkerGeometrySpec.GetForChassis(visual.ModelId);
|
||||||
|
string id = visual.ModelId.ToLowerInvariant();
|
||||||
|
var legs = new WalkerLegBinding[geom.LegCount];
|
||||||
|
|
||||||
|
for (int i = 0; i < geom.LegCount; i++)
|
||||||
|
{
|
||||||
|
string? coxaName = null;
|
||||||
|
string thighName, shinName, footName;
|
||||||
|
string? cannonName = null;
|
||||||
|
|
||||||
|
switch (id)
|
||||||
|
{
|
||||||
|
case "breaker":
|
||||||
|
{
|
||||||
|
string s = i == 0 ? "L" : "R";
|
||||||
|
thighName = $"Leg{s}.Hip";
|
||||||
|
shinName = $"Leg{s}.Shin";
|
||||||
|
footName = $"Leg{s}.Foot";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "paladin":
|
||||||
|
{
|
||||||
|
string s = i == 0 ? "L" : "R";
|
||||||
|
thighName = $"Leg{s}.Upper";
|
||||||
|
shinName = $"Leg{s}.Lower";
|
||||||
|
footName = $"Leg{s}.Ankle";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "raptor":
|
||||||
|
case "exemplar_frame":
|
||||||
|
{
|
||||||
|
string s = i == 0 ? "L" : "R";
|
||||||
|
thighName = $"Leg{s}.Thigh";
|
||||||
|
shinName = $"Leg{s}.Shin";
|
||||||
|
cannonName = $"Leg{s}.Cannon";
|
||||||
|
footName = $"Foot{s}";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "spectre":
|
||||||
|
{
|
||||||
|
string s = i == 0 ? "L" : "R";
|
||||||
|
thighName = $"Leg{s}.Thigh";
|
||||||
|
shinName = $"Leg{s}.Shin";
|
||||||
|
cannonName = $"Leg{s}.Cannon";
|
||||||
|
footName = $"Leg{s}.Ankle";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "kestrel":
|
||||||
|
{
|
||||||
|
string s = i == 0 ? "L" : "R";
|
||||||
|
thighName = $"Leg{s}.Thigh";
|
||||||
|
shinName = $"Leg{s}.Shin";
|
||||||
|
footName = $"Leg{s}.Foot";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "manticore":
|
||||||
|
{
|
||||||
|
string q = i switch { 0 => "FL", 1 => "FR", 2 => "BL", _ => "BR" };
|
||||||
|
coxaName = $"Leg{q}.Coxa";
|
||||||
|
thighName = $"Leg{q}.S1";
|
||||||
|
shinName = $"Leg{q}.S2";
|
||||||
|
footName = $"Foot{q}";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "bastion":
|
||||||
|
{
|
||||||
|
string q = i switch { 0 => "fl", 1 => "fr", 2 => "rl", _ => "rr" };
|
||||||
|
thighName = $"Thigh.{q}";
|
||||||
|
shinName = $"Shin.{q}";
|
||||||
|
footName = $"Ankle.{q}";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (visual.GetNamedNode(thighName) is not { } thighNode ||
|
||||||
|
visual.GetNamedNode(shinName) is not { } shinNode ||
|
||||||
|
visual.GetNamedNode(footName) is not { } footNode ||
|
||||||
|
!visual.TryGetRestLocal(thighName, out var restThigh) ||
|
||||||
|
!visual.TryGetRestLocal(shinName, out var restShin) ||
|
||||||
|
!visual.TryGetRestLocal(footName, out var restFoot) ||
|
||||||
|
!visual.TryGetRestModel(thighName, out var modelThigh) ||
|
||||||
|
!visual.TryGetRestModel(shinName, out var modelShin) ||
|
||||||
|
!visual.TryGetRestModel(footName, out var modelFoot))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Node3D? cannonNode = null;
|
||||||
|
Transform3D restCannon = Transform3D.Identity;
|
||||||
|
Transform3D modelCannon = Transform3D.Identity;
|
||||||
|
if (cannonName is not null)
|
||||||
|
{
|
||||||
|
if (visual.GetNamedNode(cannonName) is not { } cn ||
|
||||||
|
!visual.TryGetRestLocal(cannonName, out restCannon) ||
|
||||||
|
!visual.TryGetRestModel(cannonName, out modelCannon))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
cannonNode = cn;
|
||||||
|
}
|
||||||
|
|
||||||
|
Node3D? coxaNode = null;
|
||||||
|
Transform3D restCoxa = Transform3D.Identity;
|
||||||
|
Transform3D modelCoxa = Transform3D.Identity;
|
||||||
|
if (coxaName is not null &&
|
||||||
|
visual.GetNamedNode(coxaName) is { } cxn &&
|
||||||
|
visual.TryGetRestLocal(coxaName, out restCoxa) &&
|
||||||
|
visual.TryGetRestModel(coxaName, out modelCoxa))
|
||||||
|
{
|
||||||
|
coxaNode = cxn;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 dirRestThigh = (modelShin.Origin - modelThigh.Origin).Normalized();
|
||||||
|
Vector3 shinEndOrigin = cannonNode is not null ? modelCannon.Origin : modelFoot.Origin;
|
||||||
|
Vector3 dirRestShin = (shinEndOrigin - modelShin.Origin).Normalized();
|
||||||
|
Vector3 dirRestCannon = cannonNode is not null
|
||||||
|
? (modelFoot.Origin - modelCannon.Origin).Normalized()
|
||||||
|
: Vector3.Down;
|
||||||
|
|
||||||
|
Vector3 legRightRest = geom.IsArachnidUp
|
||||||
|
? dirRestThigh.Cross(Vector3.Up).Normalized()
|
||||||
|
: ToGodot(geom.Legs[i].LegRight0);
|
||||||
|
|
||||||
|
SegmentBinding? coxaBinding = null;
|
||||||
|
if (coxaNode is not null)
|
||||||
|
{
|
||||||
|
Vector3 rad0 = new(modelFoot.Origin.X - modelThigh.Origin.X, 0f, modelFoot.Origin.Z - modelThigh.Origin.Z);
|
||||||
|
rad0 = rad0.LengthSquared() > 1e-6f ? rad0.Normalized() : ToGodot(geom.Legs[i].LegFwd0);
|
||||||
|
Basis fCoxaRest = BasisFromDownAndRight(-rad0, Vector3.Up.Cross(rad0));
|
||||||
|
coxaBinding = new SegmentBinding
|
||||||
|
{
|
||||||
|
Node = coxaNode,
|
||||||
|
RestLocal = restCoxa,
|
||||||
|
IntermediateBefore = BuildIntermediateChain(visual.ModelRoot, coxaNode),
|
||||||
|
QOffset = fCoxaRest.Inverse() * modelCoxa.Basis.Orthonormalized()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var thighBinding = new SegmentBinding
|
||||||
|
{
|
||||||
|
Node = thighNode,
|
||||||
|
RestLocal = restThigh,
|
||||||
|
IntermediateBefore = BuildIntermediateChain(coxaNode ?? visual.ModelRoot, thighNode),
|
||||||
|
QOffset = BasisFromDownAndRight(dirRestThigh, legRightRest).Inverse() * modelThigh.Basis.Orthonormalized()
|
||||||
|
};
|
||||||
|
|
||||||
|
var shinBinding = new SegmentBinding
|
||||||
|
{
|
||||||
|
Node = shinNode,
|
||||||
|
RestLocal = restShin,
|
||||||
|
IntermediateBefore = BuildIntermediateChain(thighNode, shinNode),
|
||||||
|
QOffset = BasisFromDownAndRight(dirRestShin, legRightRest).Inverse() * modelShin.Basis.Orthonormalized()
|
||||||
|
};
|
||||||
|
|
||||||
|
SegmentBinding? cannonBinding = null;
|
||||||
|
if (cannonNode is not null)
|
||||||
|
{
|
||||||
|
cannonBinding = new SegmentBinding
|
||||||
|
{
|
||||||
|
Node = cannonNode,
|
||||||
|
RestLocal = restCannon,
|
||||||
|
IntermediateBefore = BuildIntermediateChain(shinNode, cannonNode),
|
||||||
|
QOffset = BasisFromDownAndRight(dirRestCannon, legRightRest).Inverse() * modelCannon.Basis.Orthonormalized()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var footBinding = new SegmentBinding
|
||||||
|
{
|
||||||
|
Node = footNode,
|
||||||
|
RestLocal = restFoot,
|
||||||
|
IntermediateBefore = BuildIntermediateChain(cannonNode ?? shinNode, footNode),
|
||||||
|
QOffset = BasisFromDownAndRight(Vector3.Down, legRightRest).Inverse() * modelFoot.Basis.Orthonormalized()
|
||||||
|
};
|
||||||
|
|
||||||
|
legs[i] = new WalkerLegBinding
|
||||||
|
{
|
||||||
|
Coxa = coxaBinding,
|
||||||
|
Thigh = thighBinding,
|
||||||
|
Shin = shinBinding,
|
||||||
|
Cannon = cannonBinding,
|
||||||
|
Foot = footBinding
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return new WalkerVisualRig
|
||||||
|
{
|
||||||
|
Geom = geom,
|
||||||
|
Legs = legs
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Node3D[] BuildIntermediateChain(Node3D ancestorExclusive, Node3D childExclusive)
|
||||||
|
{
|
||||||
|
var list = new List<Node3D>(4);
|
||||||
|
for (Node? cur = childExclusive.GetParent(); cur is Node3D n3d && !ReferenceEquals(cur, ancestorExclusive); cur = cur.GetParent())
|
||||||
|
{
|
||||||
|
list.Add(n3d);
|
||||||
|
}
|
||||||
|
list.Reverse();
|
||||||
|
return list.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Basis BasisFromDownAndRight(Vector3 downDir, Vector3 rightX)
|
||||||
|
{
|
||||||
|
Vector3 upY = -downDir.Normalized();
|
||||||
|
Vector3 x = rightX - upY * rightX.Dot(upY);
|
||||||
|
x = x.LengthSquared() > 1e-6f ? x.Normalized() : Vector3.Right;
|
||||||
|
Vector3 z = x.Cross(upY).Normalized();
|
||||||
|
x = upY.Cross(z).Normalized();
|
||||||
|
return new Basis(x, upY, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Vector3 ToGodot(System.Numerics.Vector3 v) => new(v.X, v.Y, v.Z);
|
||||||
|
|
||||||
private static void AnimateManticoreTail(
|
private static void AnimateManticoreTail(
|
||||||
VehicleVisualInstance visual,
|
VehicleVisualInstance visual,
|
||||||
RigState st,
|
RigState st,
|
||||||
|
|
@ -591,12 +802,14 @@ public static class VehicleRigAnimator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void StepBreakerMechanisms(
|
/// <summary>
|
||||||
|
/// Steps Breaker's real oleo gas-spring struts, 2-link scissor torque knees, and telescoping recess rams
|
||||||
|
/// from real Newtonian GRF per-leg load factors (<c>grfN / (0.5f * weightN)</c>).
|
||||||
|
/// </summary>
|
||||||
|
public static void StepBreakerLinkages(
|
||||||
VehicleVisualInstance visual,
|
VehicleVisualInstance visual,
|
||||||
RigState st,
|
float leftLoadG,
|
||||||
float phiL,
|
float rightLoadG,
|
||||||
float phiR,
|
|
||||||
float velY,
|
|
||||||
float dt)
|
float dt)
|
||||||
{
|
{
|
||||||
VehicleMechanismsRecord? mech = visual.Package.Mechanisms;
|
VehicleMechanismsRecord? mech = visual.Package.Mechanisms;
|
||||||
|
|
@ -605,15 +818,15 @@ public static class VehicleRigAnimator
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RigState st = visual.RigState;
|
||||||
BreakerMechRig rig = st.BreakerRig ??= InitBreakerRig(visual, mech);
|
BreakerMechRig rig = st.BreakerRig ??= InitBreakerRig(visual, mech);
|
||||||
if (!rig.Initialized)
|
if (!rig.Initialized)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
float accelY = dt > 1e-4f ? Math.Clamp((velY - st.PrevVelY) / dt, -25f, 25f) : 0f;
|
float strideLoadL = Math.Clamp(leftLoadG, 0f, 3.5f);
|
||||||
float strideLoadL = 1.0f + 0.42f * MathF.Sin(phiL) * st.StrideAmp + MathF.Max(-0.6f, accelY * 0.05f);
|
float strideLoadR = Math.Clamp(rightLoadG, 0f, 3.5f);
|
||||||
float strideLoadR = 1.0f + 0.42f * MathF.Sin(phiR) * st.StrideAmp + MathF.Max(-0.6f, accelY * 0.05f);
|
|
||||||
|
|
||||||
// 1. Oleo gas-spring + asymmetric orifice damping (Brokkr mechrig.Model.strut_step)
|
// 1. Oleo gas-spring + asymmetric orifice damping (Brokkr mechrig.Model.strut_step)
|
||||||
if (dt > 0f)
|
if (dt > 0f)
|
||||||
|
|
@ -664,7 +877,7 @@ public static class VehicleRigAnimator
|
||||||
Vector3 bInShin = forkInShin * sb.BInOleoFork;
|
Vector3 bInShin = forkInShin * sb.BInOleoFork;
|
||||||
Vector3 apexInShin = SolveScissorApex(sb.AInShin, bInShin, sb.OutInShin, sb.Arm);
|
Vector3 apexInShin = SolveScissorApex(sb.AInShin, bInShin, sb.OutInShin, sb.Arm);
|
||||||
|
|
||||||
Vector3 dirUp = (apexInShin - sb.AInShin);
|
Vector3 dirUp = apexInShin - sb.AInShin;
|
||||||
if (dirUp.LengthSquared() > 1e-8f)
|
if (dirUp.LengthSquared() > 1e-8f)
|
||||||
{
|
{
|
||||||
Quaternion qUp = ShortestArcQuat(sb.DirUp0InShin, dirUp.Normalized());
|
Quaternion qUp = ShortestArcQuat(sb.DirUp0InShin, dirUp.Normalized());
|
||||||
|
|
@ -673,7 +886,7 @@ public static class VehicleRigAnimator
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 apexInFork = forkInShin.Inverse() * apexInShin;
|
Vector3 apexInFork = forkInShin.Inverse() * apexInShin;
|
||||||
Vector3 dirLow = (apexInFork - sb.BInOleoFork);
|
Vector3 dirLow = apexInFork - sb.BInOleoFork;
|
||||||
if (dirLow.LengthSquared() > 1e-8f)
|
if (dirLow.LengthSquared() > 1e-8f)
|
||||||
{
|
{
|
||||||
Quaternion qLow = ShortestArcQuat(sb.DirLow0InOleoFork, dirLow.Normalized());
|
Quaternion qLow = ShortestArcQuat(sb.DirLow0InOleoFork, dirLow.Normalized());
|
||||||
|
|
@ -780,7 +993,6 @@ public static class VehicleRigAnimator
|
||||||
|
|
||||||
foreach (var r in mech.Rams)
|
foreach (var r in mech.Rams)
|
||||||
{
|
{
|
||||||
// Name: "LegL.RecessRam0" -> lug "LegL.RamLugA0", oleo "LegL.Oleo", foot "LegL.Foot"
|
|
||||||
string side = r.Name.StartsWith("LegR", StringComparison.Ordinal) ? "R" : "L";
|
string side = r.Name.StartsWith("LegR", StringComparison.Ordinal) ? "R" : "L";
|
||||||
char idxChar = r.Name[^1];
|
char idxChar = r.Name[^1];
|
||||||
string lugName = $"Leg{side}.RamLugA{idxChar}";
|
string lugName = $"Leg{side}.RamLugA{idxChar}";
|
||||||
|
|
@ -850,190 +1062,6 @@ public static class VehicleRigAnimator
|
||||||
j.Node.Transform = new Transform3D(delta * j.RestLocal.Basis, j.RestLocal.Origin);
|
j.Node.Transform = new Transform3D(delta * j.RestLocal.Basis, j.RestLocal.Origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RotateVehicleAxis(VehicleVisualInstance visual, string nodeName, Vector3 vehicleAxis, float angleRad)
|
|
||||||
{
|
|
||||||
if (visual.GetNamedNode(nodeName) is not { } node ||
|
|
||||||
!visual.TryGetRestLocal(nodeName, out var rest))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 axisInParent = vehicleAxis;
|
|
||||||
if (node.GetParent() is Node3D p3 && visual.TryGetRestModel(p3, out var pModel))
|
|
||||||
{
|
|
||||||
axisInParent = (pModel.Basis.Orthonormalized().Inverse() * vehicleAxis).Normalized();
|
|
||||||
}
|
|
||||||
Basis delta = new Basis(axisInParent, angleRad);
|
|
||||||
node.Transform = new Transform3D(delta * rest.Basis, rest.Origin);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void EnsureWalkerFootSamples(VehicleVisualInstance visual, RigState st)
|
|
||||||
{
|
|
||||||
if (st.FootSamples is not null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var list = new List<WalkerFootSample>();
|
|
||||||
float cutoffY = visual.Template.MinY + 0.75f;
|
|
||||||
var parts = visual.StaticParts;
|
|
||||||
|
|
||||||
for (int i = 0; i < parts.Count; i++)
|
|
||||||
{
|
|
||||||
var part = parts[i];
|
|
||||||
if (!GodotObject.IsInstanceValid(part.Pivot))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build chain from ModelRoot -> part.Pivot
|
|
||||||
var chain = new List<Node3D>();
|
|
||||||
Transform3D toModel = Transform3D.Identity;
|
|
||||||
for (Node? cur = part.Pivot; cur is Node3D n3d && !ReferenceEquals(cur, visual.ModelRoot); cur = cur.GetParent())
|
|
||||||
{
|
|
||||||
chain.Add(n3d);
|
|
||||||
toModel = n3d.Transform * toModel;
|
|
||||||
}
|
|
||||||
chain.Reverse();
|
|
||||||
|
|
||||||
Aabb aabb = part.Mesh.GetAabb();
|
|
||||||
float aabbMinY = float.PositiveInfinity;
|
|
||||||
for (int c = 0; c < 8; c++)
|
|
||||||
{
|
|
||||||
Vector3 corner = aabb.Position + new Vector3(
|
|
||||||
(c & 1) != 0 ? aabb.Size.X : 0f,
|
|
||||||
(c & 2) != 0 ? aabb.Size.Y : 0f,
|
|
||||||
(c & 4) != 0 ? aabb.Size.Z : 0f);
|
|
||||||
float wy = (toModel * corner).Y;
|
|
||||||
if (wy < aabbMinY)
|
|
||||||
{
|
|
||||||
aabbMinY = wy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aabbMinY >= cutoffY)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var bestPts = new Vector3[FootSupportDirs.Length];
|
|
||||||
var bestDots = new float[FootSupportDirs.Length];
|
|
||||||
for (int d = 0; d < FootSupportDirs.Length; d++)
|
|
||||||
{
|
|
||||||
bestDots[d] = float.NegativeInfinity;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool anyVert = false;
|
|
||||||
int surfCount = part.Mesh.GetSurfaceCount();
|
|
||||||
for (int s = 0; s < surfCount; s++)
|
|
||||||
{
|
|
||||||
var arrays = part.Mesh.SurfaceGetArrays(s);
|
|
||||||
if (arrays.Count <= (int)Mesh.ArrayType.Vertex ||
|
|
||||||
arrays[(int)Mesh.ArrayType.Vertex].VariantType != Variant.Type.PackedVector3Array)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Vector3[] verts = arrays[(int)Mesh.ArrayType.Vertex].AsVector3Array();
|
|
||||||
for (int v = 0; v < verts.Length; v++)
|
|
||||||
{
|
|
||||||
Vector3 localPt = verts[v];
|
|
||||||
Vector3 mPt = toModel * localPt;
|
|
||||||
for (int d = 0; d < FootSupportDirs.Length; d++)
|
|
||||||
{
|
|
||||||
float score = mPt.Dot(FootSupportDirs[d]);
|
|
||||||
if (score > bestDots[d])
|
|
||||||
{
|
|
||||||
bestDots[d] = score;
|
|
||||||
bestPts[d] = localPt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
anyVert = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (anyVert)
|
|
||||||
{
|
|
||||||
var unique = new List<Vector3>(FootSupportDirs.Length);
|
|
||||||
for (int d = 0; d < bestPts.Length; d++)
|
|
||||||
{
|
|
||||||
bool dup = false;
|
|
||||||
for (int u = 0; u < unique.Count; u++)
|
|
||||||
{
|
|
||||||
if ((unique[u] - bestPts[d]).LengthSquared() < 1e-6f)
|
|
||||||
{
|
|
||||||
dup = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!dup)
|
|
||||||
{
|
|
||||||
unique.Add(bestPts[d]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
list.Add(new WalkerFootSample
|
|
||||||
{
|
|
||||||
ChainFromModelRoot = chain.ToArray(),
|
|
||||||
LocalPoints = unique.ToArray()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
st.FootSamples = list;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static readonly Vector3[] FootSupportDirs =
|
|
||||||
{
|
|
||||||
new(0f, -1f, 0f),
|
|
||||||
new(0.45f, -1f, 0f),
|
|
||||||
new(-0.45f, -1f, 0f),
|
|
||||||
new(0f, -1f, 0.45f),
|
|
||||||
new(0f, -1f, -0.45f),
|
|
||||||
new(0.45f, -1f, 0.45f),
|
|
||||||
new(0.45f, -1f, -0.45f),
|
|
||||||
new(-0.45f, -1f, 0.45f),
|
|
||||||
new(-0.45f, -1f, -0.45f),
|
|
||||||
};
|
|
||||||
|
|
||||||
private static void ApplyWalkerFloorClearance(VehicleVisualInstance visual, RigState st, string rootNodeName)
|
|
||||||
{
|
|
||||||
var samples = st.FootSamples;
|
|
||||||
if (samples is null || samples.Count == 0 || visual.GetNamedNode(rootNodeName) is not { } rootNode)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
float minModelY = float.PositiveInfinity;
|
|
||||||
for (int i = 0; i < samples.Count; i++)
|
|
||||||
{
|
|
||||||
var s = samples[i];
|
|
||||||
Transform3D toModel = Transform3D.Identity;
|
|
||||||
for (int k = 0; k < s.ChainFromModelRoot.Length; k++)
|
|
||||||
{
|
|
||||||
toModel *= s.ChainFromModelRoot[k].Transform;
|
|
||||||
}
|
|
||||||
for (int p = 0; p < s.LocalPoints.Length; p++)
|
|
||||||
{
|
|
||||||
float y = (toModel * s.LocalPoints[p]).Y;
|
|
||||||
if (y < minModelY)
|
|
||||||
{
|
|
||||||
minModelY = y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float restMinY = visual.Template.MinY;
|
|
||||||
if (float.IsFinite(minModelY) && minModelY < restMinY)
|
|
||||||
{
|
|
||||||
Vector3 liftInModel = new Vector3(0f, restMinY - minModelY, 0f);
|
|
||||||
Vector3 liftInParent = liftInModel;
|
|
||||||
if (rootNode.GetParent() is Node3D p3 && visual.TryGetRestModel(p3, out var pModel))
|
|
||||||
{
|
|
||||||
liftInParent = pModel.Basis.Orthonormalized().Inverse() * liftInModel;
|
|
||||||
}
|
|
||||||
rootNode.Transform = new Transform3D(rootNode.Transform.Basis, rootNode.Transform.Origin + liftInParent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Quaternion ShortestArcQuat(Vector3 from, Vector3 to)
|
private static Quaternion ShortestArcQuat(Vector3 from, Vector3 to)
|
||||||
{
|
{
|
||||||
float dot = Math.Clamp(from.Dot(to), -1f, 1f);
|
float dot = Math.Clamp(from.Dot(to), -1f, 1f);
|
||||||
|
|
|
||||||
|
|
@ -724,7 +724,7 @@ public partial class Smoke : Node
|
||||||
new VehicleRigDriveInput(new Vector3(0f, 0f, 6f), 0f, 0.70f, 18f, 0f, 0.8f, 0f, 1f, 1f / 60f),
|
new VehicleRigDriveInput(new Vector3(0f, 0f, 6f), 0f, 0.70f, 18f, 0f, 0.8f, 0f, 1f, 1f / 60f),
|
||||||
minRotRad: 0.001f);
|
minRotRad: 0.001f);
|
||||||
|
|
||||||
// Breaker: verify oleo strut slide + scissor torque links + recess ram aiming
|
// Breaker: verify oleo strut slide + scissor torque links + recess ram aiming driven by Newtonian GRF load
|
||||||
{
|
{
|
||||||
var breakerVis = VehicleVisualInstance.Create(cache, "breaker", VehicleVisualRole.Player);
|
var breakerVis = VehicleVisualInstance.Create(cache, "breaker", VehicleVisualRole.Player);
|
||||||
Node3D? oleo = breakerVis.GetNamedNode("LegL.Oleo");
|
Node3D? oleo = breakerVis.GetNamedNode("LegL.Oleo");
|
||||||
|
|
@ -737,10 +737,13 @@ public partial class Smoke : Node
|
||||||
Transform3D oleo0 = oleo.Transform;
|
Transform3D oleo0 = oleo.Transform;
|
||||||
Transform3D sc0 = scissorUp.Transform;
|
Transform3D sc0 = scissorUp.Transform;
|
||||||
Transform3D ramRest = ram0.Transform;
|
Transform3D ramRest = ram0.Transform;
|
||||||
var inp1 = new VehicleRigDriveInput(new Vector3(0f, -6f, 8f), 0f, 0.4f, 10f, 0f, 1f, 0f, 1f, 1f / 60f);
|
Node3D? footL = breakerVis.GetNamedNode("LegL.Foot");
|
||||||
for (int s = 0; s < 10; s++) VehicleRigAnimator.Update(breakerVis, in inp1, Basis.Identity);
|
if (footL is not null)
|
||||||
var inp2 = new VehicleRigDriveInput(new Vector3(0f, 3f, 8f), 0f, 0.4f, 10f, 0f, 1f, 0f, 1f, 1f / 60f);
|
{
|
||||||
for (int s = 0; s < 10; s++) VehicleRigAnimator.Update(breakerVis, in inp2, Basis.Identity);
|
footL.Transform = new Transform3D(new Basis(Vector3.Right, 0.28f) * footL.Transform.Basis, footL.Transform.Origin);
|
||||||
|
}
|
||||||
|
for (int s = 0; s < 10; s++) VehicleRigAnimator.StepBreakerLinkages(breakerVis, leftLoadG: 1.85f, rightLoadG: 0.25f, dt: 1f / 60f);
|
||||||
|
for (int s = 0; s < 10; s++) VehicleRigAnimator.StepBreakerLinkages(breakerVis, leftLoadG: 0.25f, rightLoadG: 1.85f, dt: 1f / 60f);
|
||||||
|
|
||||||
float oleoDelta = (oleo.Transform.Origin - oleo0.Origin).Length();
|
float oleoDelta = (oleo.Transform.Origin - oleo0.Origin).Length();
|
||||||
float scDelta = sc0.Basis.GetRotationQuaternion().AngleTo(scissorUp.Transform.Basis.GetRotationQuaternion());
|
float scDelta = sc0.Basis.GetRotationQuaternion().AngleTo(scissorUp.Transform.Basis.GetRotationQuaternion());
|
||||||
|
|
@ -920,39 +923,73 @@ public partial class Smoke : Node
|
||||||
drops.RemoveRange(baseCount, added.Count);
|
drops.RemoveRange(baseCount, added.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. All 7 walkers stay grounded (minVertexY - restMinY >= -0.05m) and swing along +Z/-Z through a full stride cycle
|
// 6. All 7 walkers (including Kestrel) walk through real ArenaSession + Hybrid B FK snapshot cleanly
|
||||||
{
|
{
|
||||||
var walkerChecks = new (string Id, string? FootNode, string? PelvisNode, bool CheckSagittal)[]
|
using var walkSession = new RustToDust.Ymir.ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert);
|
||||||
|
for (int cIdx = 1; cIdx < walkSession.State.Contenders.Count; cIdx++)
|
||||||
{
|
{
|
||||||
("raptor", "LegL.Cannon", "Pelvis", true),
|
walkSession.SetContenderPose(cIdx, 450f + cIdx * 18f, 450f);
|
||||||
("spectre", "LegL.Cannon", "Pelvis", true),
|
}
|
||||||
("manticore", "FootFL", "Hull", true),
|
|
||||||
("bastion", "Ankle.fl", "Trunk", true),
|
var walkerChecks = new (string Id, string FootNode, string PelvisNode)[]
|
||||||
("breaker", "LegL.Foot", "Pelvis", true),
|
{
|
||||||
("paladin", "LegL.Ankle", "Pelvis", true),
|
("raptor", "FootL", "Pelvis"),
|
||||||
("kestrel", null, null, false),
|
("spectre", "LegL.Ankle", "Pelvis"),
|
||||||
|
("manticore", "FootFL", "Hull"),
|
||||||
|
("bastion", "Ankle.fl", "Trunk"),
|
||||||
|
("breaker", "LegL.Foot", "Pelvis"),
|
||||||
|
("paladin", "LegL.Ankle", "Pelvis"),
|
||||||
|
("kestrel", "LegL.Foot", "Pelvis"),
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (var (wId, footNodeName, pelvisNodeName, checkSagittal) in walkerChecks)
|
foreach (var (wId, footNodeName, pelvisNodeName) in walkerChecks)
|
||||||
{
|
{
|
||||||
|
var wSpec = Catalog.ChassisById[wId];
|
||||||
|
walkSession.SetContenderPose(0, 0f, 0f, 0f);
|
||||||
|
if (walkSession.State.Player.Grid.Spec.Id != wId)
|
||||||
|
{
|
||||||
|
walkSession.State.SpawnChassisDrop(0f, 0f, wSpec);
|
||||||
|
Check(walkSession.TrySwapNearbyChassis(), $"Failed to swap walkSession player to '{wId}'");
|
||||||
|
}
|
||||||
|
|
||||||
var vis = VehicleVisualInstance.Create(cache, wId, VehicleVisualRole.Player);
|
var vis = VehicleVisualInstance.Create(cache, wId, VehicleVisualRole.Player);
|
||||||
float restMinY = vis.ComputeMinVertexY(relativeToModelRoot: true);
|
|
||||||
float worstRelMinY = float.PositiveInfinity;
|
float worstRelMinY = float.PositiveInfinity;
|
||||||
float minFootZ = float.PositiveInfinity, maxFootZ = float.NegativeInfinity;
|
float minFootZ = float.PositiveInfinity, maxFootZ = float.NegativeInfinity;
|
||||||
float minFootX = float.PositiveInfinity, maxFootX = float.NegativeInfinity;
|
float minFootX = float.PositiveInfinity, maxFootX = float.NegativeInfinity;
|
||||||
Node3D? footNode = footNodeName is not null ? vis.GetNamedNode(footNodeName) : null;
|
Node3D? footNode = vis.GetNamedNode(footNodeName);
|
||||||
Node3D? pelvisNode = pelvisNodeName is not null ? vis.GetNamedNode(pelvisNodeName) : null;
|
Node3D? pelvisNode = vis.GetNamedNode(pelvisNodeName);
|
||||||
|
Check(footNode is not null && pelvisNode is not null,
|
||||||
|
$"Missing FK nodes '{footNodeName}'/'{pelvisNodeName}' on walker '{wId}'");
|
||||||
|
|
||||||
var walkInp = new VehicleRigDriveInput(
|
var player = walkSession.State.Player;
|
||||||
new Vector3(0f, 0f, 8f), 0f, 0f, 0f, 0f, 1f, 0f, 1f, 0.05f);
|
for (int step = 0; step < 60; step++)
|
||||||
|
|
||||||
for (int step = 0; step < 48; step++)
|
|
||||||
{
|
{
|
||||||
VehicleRigAnimator.Update(vis, in walkInp, Basis.Identity);
|
walkSession.Step(new PlayerInput(
|
||||||
float curMinY = vis.ComputeMinVertexY(relativeToModelRoot: true);
|
Throttle: 1f,
|
||||||
float relMinY = curMinY - restMinY;
|
Steer: 0f,
|
||||||
if (relMinY < worstRelMinY) worstRelMinY = relMinY;
|
AimWorldX: player.X,
|
||||||
Check(!float.IsNaN(curMinY), $"NaN vertex Y on walker '{wId}' step {step}");
|
AimWorldZ: player.Z + 50f,
|
||||||
|
Fire: false,
|
||||||
|
InteractPickup: false,
|
||||||
|
Brake: false));
|
||||||
|
|
||||||
|
bool hasSnap = walkSession.TrySampleInterpolatedWalkerPose(true, player.Id, 1f, out var walkerSnap);
|
||||||
|
Check(hasSnap, $"Missing WalkerVisualSnapshot for '{wId}' at step {step}");
|
||||||
|
if (!hasSnap) break;
|
||||||
|
|
||||||
|
var (interpPos, interpRot, interpVel) = walkSession.GetInterpolatedContenderPose(player.Id, 1f);
|
||||||
|
var q = new Quaternion(interpRot.X, interpRot.Y, interpRot.Z, interpRot.W);
|
||||||
|
vis.Root.Transform = new Transform3D(new Basis(q), new Vector3(interpPos.X, interpPos.Y, interpPos.Z));
|
||||||
|
VehicleRigAnimator.Update(
|
||||||
|
vis,
|
||||||
|
player,
|
||||||
|
new Vector3(interpVel.X, interpVel.Y, interpVel.Z),
|
||||||
|
vis.Root.Basis,
|
||||||
|
1f / 60f,
|
||||||
|
in walkerSnap);
|
||||||
|
|
||||||
|
float curMinWorldY = vis.ComputeMinVertexY(relativeToModelRoot: false);
|
||||||
|
Check(!float.IsNaN(curMinWorldY), $"NaN vertex Y on walker '{wId}' step {step}");
|
||||||
|
|
||||||
if (footNode is not null && pelvisNode is not null)
|
if (footNode is not null && pelvisNode is not null)
|
||||||
{
|
{
|
||||||
|
|
@ -961,20 +998,24 @@ public partial class Smoke : Node
|
||||||
if (fPos.Z > maxFootZ) maxFootZ = fPos.Z;
|
if (fPos.Z > maxFootZ) maxFootZ = fPos.Z;
|
||||||
if (fPos.X < minFootX) minFootX = fPos.X;
|
if (fPos.X < minFootX) minFootX = fPos.X;
|
||||||
if (fPos.X > maxFootX) maxFootX = fPos.X;
|
if (fPos.X > maxFootX) maxFootX = fPos.X;
|
||||||
|
|
||||||
|
Vector3 fInModel = TransformPointToAncestor(footNode, vis.ModelRoot, Vector3.Zero);
|
||||||
|
Vector3 fWorld = vis.Root.Transform * (vis.ModelRoot.Transform * fInModel);
|
||||||
|
float groundUnderFoot = walkSession.State.Terrain.SampleHeight(fWorld.X, fWorld.Z);
|
||||||
|
float relMinY = curMinWorldY - groundUnderFoot;
|
||||||
|
if (relMinY < worstRelMinY) worstRelMinY = relMinY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float zSpan = footNode is not null ? maxFootZ - minFootZ : 0f;
|
float zSpan = footNode is not null ? maxFootZ - minFootZ : 0f;
|
||||||
float xSpan = footNode is not null ? maxFootX - minFootX : 0f;
|
float xSpan = footNode is not null ? maxFootX - minFootX : 0f;
|
||||||
GD.Print($"SMOKE INFO: Walker {wId} stride minFootY={worstRelMinY:F4}m zSpan={zSpan:F3}m xSpan={xSpan:F3}m");
|
GD.Print($"SMOKE INFO: HybridB Walker {wId} minWorldFootRelY={worstRelMinY:F4}m zSpan={zSpan:F3}m xSpan={xSpan:F3}m");
|
||||||
Check(worstRelMinY >= -0.05f,
|
Check(worstRelMinY >= -0.25f,
|
||||||
$"Walker '{wId}' foot plunged below rest floor: minRelY={worstRelMinY:F4}m");
|
$"Walker '{wId}' plunged below terrain: minRelY={worstRelMinY:F4}m");
|
||||||
if (checkSagittal && footNode is not null)
|
if (footNode is not null)
|
||||||
{
|
{
|
||||||
Check(zSpan > 0.12f,
|
Check(zSpan > 0.12f,
|
||||||
$"Expected walker '{wId}' foot '{footNodeName}' to stride along Z > 0.12m, got {zSpan:F3}m");
|
$"Expected walker '{wId}' foot '{footNodeName}' to stride along Z > 0.12m through Hybrid B FK, got {zSpan:F3}m");
|
||||||
Check(xSpan < 0.03f,
|
|
||||||
$"Expected walker '{wId}' foot '{footNodeName}' to swing cleanly in sagittal plane (xSpan < 0.03m), got {xSpan:F3}m");
|
|
||||||
}
|
}
|
||||||
vis.Root.QueueFree();
|
vis.Root.QueueFree();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -604,15 +604,117 @@ namespace RustToDust.Core
|
||||||
return dropped;
|
return dropped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void GetLegIntegrities(Span<float> outLegs)
|
||||||
|
{
|
||||||
|
if (Spec.Plane == GridPlane.Coronal)
|
||||||
|
{
|
||||||
|
int legStartY = Math.Max(0, Spec.Height - 2);
|
||||||
|
int leftMaxX = Spec.Width / 2;
|
||||||
|
int rightMinX = (Spec.Width + 1) / 2;
|
||||||
|
float curL = 0f, maxL = 0f, curR = 0f, maxR = 0f;
|
||||||
|
|
||||||
|
for (int y = legStartY; y < Spec.Height; y++)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < Spec.Width; x++)
|
||||||
|
{
|
||||||
|
if (!Spec.IsActive(x, y))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (x < leftMaxX)
|
||||||
|
{
|
||||||
|
curL += Armor[x, y];
|
||||||
|
maxL += MaxArmor[x, y];
|
||||||
|
}
|
||||||
|
else if (x >= rightMinX)
|
||||||
|
{
|
||||||
|
curR += Armor[x, y];
|
||||||
|
maxR += MaxArmor[x, y];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outLegs.Length > 0)
|
||||||
|
{
|
||||||
|
outLegs[0] = maxL > 0f ? 0.25f + 0.75f * Math.Clamp(curL / maxL, 0f, 1f) : 1f;
|
||||||
|
}
|
||||||
|
if (outLegs.Length > 1)
|
||||||
|
{
|
||||||
|
outLegs[1] = maxR > 0f ? 0.25f + 0.75f * Math.Clamp(curR / maxR, 0f, 1f) : 1f;
|
||||||
|
}
|
||||||
|
for (int i = 2; i < outLegs.Length; i++)
|
||||||
|
{
|
||||||
|
outLegs[i] = 1f;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Spec.IsWalker)
|
||||||
|
{
|
||||||
|
int midXLeft = Spec.Width / 2;
|
||||||
|
int midXRight = (Spec.Width + 1) / 2;
|
||||||
|
int midY = Spec.Height / 2;
|
||||||
|
Span<float> cur = stackalloc float[4];
|
||||||
|
Span<float> max = stackalloc float[4];
|
||||||
|
|
||||||
|
for (int y = 0; y < Spec.Height; y++)
|
||||||
|
{
|
||||||
|
int rowBase = y < midY ? 0 : 2;
|
||||||
|
for (int x = 0; x < Spec.Width; x++)
|
||||||
|
{
|
||||||
|
if (!Spec.IsActive(x, y))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int legIdx;
|
||||||
|
if (x < midXLeft)
|
||||||
|
{
|
||||||
|
legIdx = rowBase;
|
||||||
|
}
|
||||||
|
else if (x >= midXRight)
|
||||||
|
{
|
||||||
|
legIdx = rowBase + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
cur[legIdx] += Armor[x, y];
|
||||||
|
max[legIdx] += MaxArmor[x, y];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int count = Math.Min(4, outLegs.Length);
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
outLegs[i] = max[i] > 0f ? 0.25f + 0.75f * Math.Clamp(cur[i] / max[i], 0f, 1f) : 1f;
|
||||||
|
}
|
||||||
|
for (int i = 4; i < outLegs.Length; i++)
|
||||||
|
{
|
||||||
|
outLegs[i] = 1f;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
outLegs.Fill(1f);
|
||||||
|
}
|
||||||
|
|
||||||
public float LegIntegrity
|
public float LegIntegrity
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (Spec.Plane != GridPlane.Coronal)
|
if (!Spec.IsWalker)
|
||||||
{
|
{
|
||||||
return 1f;
|
return 1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Spec.Plane == GridPlane.Dorsal)
|
||||||
|
{
|
||||||
|
Span<float> legs = stackalloc float[4];
|
||||||
|
GetLegIntegrities(legs);
|
||||||
|
return (legs[0] + legs[1] + legs[2] + legs[3]) * 0.25f;
|
||||||
|
}
|
||||||
|
|
||||||
int legStartY = Math.Max(0, Spec.Height - 2);
|
int legStartY = Math.Max(0, Spec.Height - 2);
|
||||||
float cur = 0f;
|
float cur = 0f;
|
||||||
float max = 0f;
|
float max = 0f;
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@ namespace RustToDust.Ymir
|
||||||
private readonly Box3DSoaWorld _world;
|
private readonly Box3DSoaWorld _world;
|
||||||
private readonly Dictionary<int, Box3DSoaBodyHandle> _contenderBodies = new();
|
private readonly Dictionary<int, Box3DSoaBodyHandle> _contenderBodies = new();
|
||||||
private readonly Dictionary<int, Box3DSoaBodyHandle> _spectatorBodies = new();
|
private readonly Dictionary<int, Box3DSoaBodyHandle> _spectatorBodies = new();
|
||||||
|
private readonly Dictionary<int, WalkerState> _contenderWalkers = new();
|
||||||
|
private readonly Dictionary<int, WalkerState> _spectatorWalkers = new();
|
||||||
private readonly Dictionary<ulong, (bool IsContender, int Index)> _entityByStableId = new();
|
private readonly Dictionary<ulong, (bool IsContender, int Index)> _entityByStableId = new();
|
||||||
private readonly float[] _trackDistAccum = new float[MatchState.ContenderCount];
|
private readonly float[] _trackDistAccum = new float[MatchState.ContenderCount];
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
|
|
@ -83,6 +85,7 @@ namespace RustToDust.Ymir
|
||||||
_world.RemoveBody(oldHandle);
|
_world.RemoveBody(oldHandle);
|
||||||
_contenderBodies.Remove(contenderId);
|
_contenderBodies.Remove(contenderId);
|
||||||
}
|
}
|
||||||
|
_contenderWalkers.Remove(contenderId);
|
||||||
if (c.Alive)
|
if (c.Alive)
|
||||||
{
|
{
|
||||||
SpawnContenderBody(c);
|
SpawnContenderBody(c);
|
||||||
|
|
@ -121,6 +124,7 @@ namespace RustToDust.Ymir
|
||||||
_world.RemoveBody(oldHandle);
|
_world.RemoveBody(oldHandle);
|
||||||
_spectatorBodies.Remove(spectatorId);
|
_spectatorBodies.Remove(spectatorId);
|
||||||
}
|
}
|
||||||
|
_spectatorWalkers.Remove(spectatorId);
|
||||||
if (spec.Alive)
|
if (spec.Alive)
|
||||||
{
|
{
|
||||||
SpawnSpectatorBody(index, spec);
|
SpawnSpectatorBody(index, spec);
|
||||||
|
|
@ -193,6 +197,53 @@ namespace RustToDust.Ymir
|
||||||
new Vector3(spec.VelX, spec.VelY, spec.VelZ));
|
new Vector3(spec.VelX, spec.VelY, spec.VelZ));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WalkerState? GetWalkerState(bool isContender, int id) =>
|
||||||
|
isContender
|
||||||
|
? (_contenderWalkers.TryGetValue(id, out var cw) ? cw : null)
|
||||||
|
: (_spectatorWalkers.TryGetValue(id, out var sw) ? sw : null);
|
||||||
|
|
||||||
|
public bool TrySampleInterpolatedWalkerPose(bool isContender, int id, float alpha, out WalkerVisualSnapshot snap)
|
||||||
|
{
|
||||||
|
var dict = isContender ? _contenderWalkers : _spectatorWalkers;
|
||||||
|
if (!dict.TryGetValue(id, out var ws) || !ws.Initialized)
|
||||||
|
{
|
||||||
|
snap = default;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
snap = WalkerVisualSnapshot.Interpolate(in ws.PrevSnap, in ws.CurrSnap, alpha);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddWalkerRecoilImpulse(bool isContender, int id, Vector3 shotDirWorld, float weaponDamage)
|
||||||
|
{
|
||||||
|
var dict = isContender ? _contenderWalkers : _spectatorWalkers;
|
||||||
|
if (!dict.TryGetValue(id, out var ws))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Quaternion qBody = Quaternion.Identity;
|
||||||
|
if (isContender && id >= 0 && id < State.Contenders.Count)
|
||||||
|
{
|
||||||
|
var c = State.Contenders[id];
|
||||||
|
qBody = new Quaternion(c.CurrRotX, c.CurrRotY, c.CurrRotZ, c.CurrRotW);
|
||||||
|
}
|
||||||
|
else if (!isContender && _spectatorBodies.TryGetValue(id, out var handle))
|
||||||
|
{
|
||||||
|
var v = _world.View;
|
||||||
|
int lane = handle.Lane;
|
||||||
|
qBody = new Quaternion(v.RotationX[lane], v.RotationY[lane], v.RotationZ[lane], v.RotationW[lane]);
|
||||||
|
}
|
||||||
|
if (qBody.LengthSquared() < 1e-6f)
|
||||||
|
{
|
||||||
|
qBody = Quaternion.Identity;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qBody = Quaternion.Normalize(qBody);
|
||||||
|
}
|
||||||
|
ws.AddRecoilImpulse(shotDirWorld, qBody, weaponDamage);
|
||||||
|
}
|
||||||
|
|
||||||
public bool HasLineOfSight(float ax, float ay, float az, float bx, float by, float bz)
|
public bool HasLineOfSight(float ax, float ay, float az, float bx, float by, float bz)
|
||||||
{
|
{
|
||||||
var delta = new Vector3(bx - ax, by - ay, bz - az);
|
var delta = new Vector3(bx - ax, by - ay, bz - az);
|
||||||
|
|
@ -310,6 +361,20 @@ namespace RustToDust.Ymir
|
||||||
{
|
{
|
||||||
State.Spectators.Spectators[i].SnapPreviousPose();
|
State.Spectators.Spectators[i].SnapPreviousPose();
|
||||||
}
|
}
|
||||||
|
foreach (var ws in _contenderWalkers.Values)
|
||||||
|
{
|
||||||
|
if (ws.Initialized)
|
||||||
|
{
|
||||||
|
ws.SnapshotPrev();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (var ws in _spectatorWalkers.Values)
|
||||||
|
{
|
||||||
|
if (ws.Initialized)
|
||||||
|
{
|
||||||
|
ws.SnapshotPrev();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Step(PlayerInput input)
|
public void Step(PlayerInput input)
|
||||||
|
|
@ -461,7 +526,10 @@ namespace RustToDust.Ymir
|
||||||
private void SpawnContenderBody(ContenderState c)
|
private void SpawnContenderBody(ContenderState c)
|
||||||
{
|
{
|
||||||
var spec = c.Grid.Spec;
|
var spec = c.Grid.Spec;
|
||||||
float volume = 8f * spec.HalfWidth * spec.HalfHeight * spec.HalfLength;
|
float physHalfH = spec.IsWalker
|
||||||
|
? spec.HalfHeight * (spec.Plane == GridPlane.Dorsal ? 0.58f : 0.72f)
|
||||||
|
: spec.HalfHeight;
|
||||||
|
float volume = 8f * spec.HalfWidth * physHalfH * spec.HalfLength;
|
||||||
float density = spec.MassKg / MathF.Max(0.1f, volume);
|
float density = spec.MassKg / MathF.Max(0.1f, volume);
|
||||||
var q = Quaternion.CreateFromAxisAngle(Vector3.UnitY, c.Yaw);
|
var q = Quaternion.CreateFromAxisAngle(Vector3.UnitY, c.Yaw);
|
||||||
ulong stableId = ContenderStableIdBase + (ulong)c.Id;
|
ulong stableId = ContenderStableIdBase + (ulong)c.Id;
|
||||||
|
|
@ -474,7 +542,7 @@ namespace RustToDust.Ymir
|
||||||
var handle = _world.AddBox(
|
var handle = _world.AddBox(
|
||||||
stableId,
|
stableId,
|
||||||
(c.X, spawnY, c.Z),
|
(c.X, spawnY, c.Z),
|
||||||
(spec.HalfWidth, spec.HalfHeight, spec.HalfLength),
|
(spec.HalfWidth, physHalfH, spec.HalfLength),
|
||||||
density,
|
density,
|
||||||
(q.X, q.Y, q.Z, q.W),
|
(q.X, q.Y, q.Z, q.W),
|
||||||
friction: 0.2f,
|
friction: 0.2f,
|
||||||
|
|
@ -491,6 +559,17 @@ namespace RustToDust.Ymir
|
||||||
c.VelZ = 0f;
|
c.VelZ = 0f;
|
||||||
c.SnapPreviousPose();
|
c.SnapPreviousPose();
|
||||||
c.ResetAimTracker(c.Yaw);
|
c.ResetAimTracker(c.Yaw);
|
||||||
|
|
||||||
|
if (spec.IsWalker)
|
||||||
|
{
|
||||||
|
var ws = new WalkerState(spec);
|
||||||
|
ws.InitializePose(new Vector3(c.X, spawnY, c.Z), q, spec.MassKg, State.Terrain);
|
||||||
|
_contenderWalkers[c.Id] = ws;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_contenderWalkers.Remove(c.Id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnContenderChassisSwapped(ContenderState c)
|
private void OnContenderChassisSwapped(ContenderState c)
|
||||||
|
|
@ -500,6 +579,7 @@ namespace RustToDust.Ymir
|
||||||
_world.RemoveBody(oldHandle);
|
_world.RemoveBody(oldHandle);
|
||||||
_contenderBodies.Remove(c.Id);
|
_contenderBodies.Remove(c.Id);
|
||||||
}
|
}
|
||||||
|
_contenderWalkers.Remove(c.Id);
|
||||||
if (c.Alive)
|
if (c.Alive)
|
||||||
{
|
{
|
||||||
SpawnContenderBody(c);
|
SpawnContenderBody(c);
|
||||||
|
|
@ -522,7 +602,10 @@ namespace RustToDust.Ymir
|
||||||
private void SpawnSpectatorBody(int index, SpectatorState s)
|
private void SpawnSpectatorBody(int index, SpectatorState s)
|
||||||
{
|
{
|
||||||
var spec = s.Grid.Spec;
|
var spec = s.Grid.Spec;
|
||||||
float volume = 8f * spec.HalfWidth * spec.HalfHeight * spec.HalfLength;
|
float physHalfH = spec.IsWalker
|
||||||
|
? spec.HalfHeight * (spec.Plane == GridPlane.Dorsal ? 0.58f : 0.72f)
|
||||||
|
: spec.HalfHeight;
|
||||||
|
float volume = 8f * spec.HalfWidth * physHalfH * spec.HalfLength;
|
||||||
float density = spec.MassKg / MathF.Max(0.1f, volume);
|
float density = spec.MassKg / MathF.Max(0.1f, volume);
|
||||||
var q = Quaternion.CreateFromAxisAngle(Vector3.UnitY, s.Yaw);
|
var q = Quaternion.CreateFromAxisAngle(Vector3.UnitY, s.Yaw);
|
||||||
ulong stableId = SpectatorStableIdBase + (ulong)s.Id;
|
ulong stableId = SpectatorStableIdBase + (ulong)s.Id;
|
||||||
|
|
@ -532,7 +615,7 @@ namespace RustToDust.Ymir
|
||||||
var handle = _world.AddBox(
|
var handle = _world.AddBox(
|
||||||
stableId,
|
stableId,
|
||||||
(s.X, spawnY, s.Z),
|
(s.X, spawnY, s.Z),
|
||||||
(spec.HalfWidth, spec.HalfHeight, spec.HalfLength),
|
(spec.HalfWidth, physHalfH, spec.HalfLength),
|
||||||
density,
|
density,
|
||||||
(q.X, q.Y, q.Z, q.W),
|
(q.X, q.Y, q.Z, q.W),
|
||||||
friction: 0.2f,
|
friction: 0.2f,
|
||||||
|
|
@ -549,6 +632,17 @@ namespace RustToDust.Ymir
|
||||||
s.VelZ = 0f;
|
s.VelZ = 0f;
|
||||||
s.SnapPreviousPose();
|
s.SnapPreviousPose();
|
||||||
s.ResetAimTracker(s.Yaw);
|
s.ResetAimTracker(s.Yaw);
|
||||||
|
|
||||||
|
if (spec.IsWalker)
|
||||||
|
{
|
||||||
|
var ws = new WalkerState(spec);
|
||||||
|
ws.InitializePose(new Vector3(s.X, spawnY, s.Z), q, spec.MassKg, State.Terrain);
|
||||||
|
_spectatorWalkers[s.Id] = ws;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_spectatorWalkers.Remove(s.Id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateRingClearance()
|
private void UpdateRingClearance()
|
||||||
|
|
@ -628,6 +722,40 @@ namespace RustToDust.Ymir
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (c.Grid.Spec.IsWalker)
|
||||||
|
{
|
||||||
|
if (!_contenderWalkers.TryGetValue(c.Id, out var ws))
|
||||||
|
{
|
||||||
|
ws = new WalkerState(c.Grid.Spec);
|
||||||
|
ws.InitializePose(pos, q, mass, State.Terrain);
|
||||||
|
_contenderWalkers[c.Id] = ws;
|
||||||
|
}
|
||||||
|
|
||||||
|
var wFwd = Vector3.Transform(Vector3.UnitZ, q);
|
||||||
|
wFwd.Y = 0f;
|
||||||
|
wFwd = wFwd.LengthSquared() < 1e-4f ? Vector3.UnitZ : Vector3.Normalize(wFwd);
|
||||||
|
float wMaxSpeed = MathF.Max(4f, c.Grid.Spec.MaxSpeed) * c.Grid.LegIntegrity;
|
||||||
|
Vector3 desiredHorizVel = wFwd * (c.ThrottleCmd * wMaxSpeed);
|
||||||
|
float wTargetYawVel = -c.SteerCmd * c.Grid.ComputeTurnRate();
|
||||||
|
|
||||||
|
if (MathF.Abs(c.ThrottleCmd) > 0.05f)
|
||||||
|
{
|
||||||
|
for (int m = 0; m < c.Grid.Mounted.Count; m++)
|
||||||
|
{
|
||||||
|
var mod = c.Grid.Mounted[m];
|
||||||
|
if (mod.Spec.Kind == HardpointKind.Engine && mod.Spec.HeatOutput > 0f)
|
||||||
|
{
|
||||||
|
c.Grid.InjectHardpointHeat(mod.HardpointId, mod.Spec.HeatOutput * MathF.Abs(c.ThrottleCmd) * FixedDt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WalkerLocomotion.StepWalker(
|
||||||
|
ws, c.Grid, State.Terrain, view, lane, mass,
|
||||||
|
pos, q, vel, angVel, desiredHorizVel, wTargetYawVel, c.BrakeCmd, FixedDt);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
ComputeTerrainSupport(
|
ComputeTerrainSupport(
|
||||||
pos, q, vel, angVel, mass, c.Grid.Spec,
|
pos, q, vel, angVel, mass, c.Grid.Spec,
|
||||||
out Vector3 supportForce,
|
out Vector3 supportForce,
|
||||||
|
|
@ -763,6 +891,30 @@ namespace RustToDust.Ymir
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector3 desiredVel = dist > 0.5f ? Vector3.Normalize(toGoal) * MathF.Min(s.MaxSpeed, dist * 1.5f) : Vector3.Zero;
|
||||||
|
float desiredYaw = s.Stance == SpectatorStance.Neutral
|
||||||
|
? MathF.Atan2(-pos.X, -pos.Z)
|
||||||
|
: MathF.Atan2(aimX - pos.X, aimZ - pos.Z);
|
||||||
|
var forward = Vector3.Transform(Vector3.UnitZ, q);
|
||||||
|
float currentYaw = MathF.Atan2(forward.X, forward.Z);
|
||||||
|
float yawErr = MatchRules.NormalizeAngle(desiredYaw - currentYaw);
|
||||||
|
float targetSpecYawVel = Math.Clamp(yawErr * 3f, -5f, 5f);
|
||||||
|
|
||||||
|
if (s.Grid.Spec.IsWalker)
|
||||||
|
{
|
||||||
|
if (!_spectatorWalkers.TryGetValue(s.Id, out var ws))
|
||||||
|
{
|
||||||
|
ws = new WalkerState(s.Grid.Spec);
|
||||||
|
ws.InitializePose(pos, q, mass, State.Terrain);
|
||||||
|
_spectatorWalkers[s.Id] = ws;
|
||||||
|
}
|
||||||
|
|
||||||
|
WalkerLocomotion.StepWalker(
|
||||||
|
ws, s.Grid, State.Terrain, view, lane, mass,
|
||||||
|
pos, q, vel, angVel, desiredVel, targetSpecYawVel, brakeCmd: false, FixedDt);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
ComputeTerrainSupport(
|
ComputeTerrainSupport(
|
||||||
pos, q, vel, angVel, mass, s.Grid.Spec,
|
pos, q, vel, angVel, mass, s.Grid.Spec,
|
||||||
out Vector3 supportForce,
|
out Vector3 supportForce,
|
||||||
|
|
@ -770,23 +922,15 @@ namespace RustToDust.Ymir
|
||||||
out Vector3 terrainNormal,
|
out Vector3 terrainNormal,
|
||||||
out _);
|
out _);
|
||||||
|
|
||||||
Vector3 desiredVel = dist > 0.5f ? Vector3.Normalize(toGoal) * MathF.Min(s.MaxSpeed, dist * 1.5f) : Vector3.Zero;
|
|
||||||
Vector3 horizVel = new Vector3(vel.X, 0f, vel.Z);
|
Vector3 horizVel = new Vector3(vel.X, 0f, vel.Z);
|
||||||
Vector3 force = supportForce + (desiredVel - horizVel) * (mass * 4.5f);
|
Vector3 force = supportForce + (desiredVel - horizVel) * (mass * 4.5f);
|
||||||
|
|
||||||
float desiredYaw = s.Stance == SpectatorStance.Neutral
|
|
||||||
? MathF.Atan2(-pos.X, -pos.Z)
|
|
||||||
: MathF.Atan2(aimX - pos.X, aimZ - pos.Z);
|
|
||||||
var forward = Vector3.Transform(Vector3.UnitZ, q);
|
|
||||||
float currentYaw = MathF.Atan2(forward.X, forward.Z);
|
|
||||||
float yawErr = MatchRules.NormalizeAngle(desiredYaw - currentYaw);
|
|
||||||
|
|
||||||
float hx = view.Size0[lane];
|
float hx = view.Size0[lane];
|
||||||
float hz = view.Size2[lane];
|
float hz = view.Size2[lane];
|
||||||
float iy = mass * (hx * hx + hz * hz) / 3f;
|
float iy = mass * (hx * hx + hz * hz) / 3f;
|
||||||
|
|
||||||
Vector3 torque = ComputeRightingTorque(s.Grid.Spec, q, up, angVel, mass, terrainNormal, supportTorque, terrainBlend: 0.7f);
|
Vector3 torque = ComputeRightingTorque(s.Grid.Spec, q, up, angVel, mass, terrainNormal, supportTorque, terrainBlend: 0.7f);
|
||||||
torque.Y = iy * (Math.Clamp(yawErr * 3f, -5f, 5f) - angVel.Y) * 8f;
|
torque.Y = iy * (targetSpecYawVel - angVel.Y) * 8f;
|
||||||
|
|
||||||
view.ForceX[lane] = force.X;
|
view.ForceX[lane] = force.X;
|
||||||
view.ForceY[lane] = force.Y;
|
view.ForceY[lane] = force.Y;
|
||||||
|
|
@ -1013,13 +1157,9 @@ namespace RustToDust.Ymir
|
||||||
Vector3 supportTorque,
|
Vector3 supportTorque,
|
||||||
float terrainBlend)
|
float terrainBlend)
|
||||||
{
|
{
|
||||||
bool isWalker = spec.IsWalker;
|
Vector3 desiredUp = Vector3.Normalize(Vector3.Lerp(Vector3.UnitY, terrainNormal, terrainBlend));
|
||||||
float blend = isWalker ? MathF.Min(terrainBlend, 0.30f) : terrainBlend;
|
|
||||||
Vector3 desiredUp = Vector3.Normalize(Vector3.Lerp(Vector3.UnitY, terrainNormal, blend));
|
|
||||||
|
|
||||||
float maxDesiredTiltRad = isWalker
|
const float maxDesiredTiltRad = MathF.PI * 38f / 180f; // 38 degrees max slope alignment so cliff walls don't back-flip vehicles
|
||||||
? MathF.PI / 15f // 12 degrees target cap so dynamic overshoot stays <= 15-20 deg
|
|
||||||
: MathF.PI * 38f / 180f; // 38 degrees max slope alignment so cliff walls don't back-flip vehicles
|
|
||||||
{
|
{
|
||||||
float dotY = Math.Clamp(desiredUp.Y, -1f, 1f);
|
float dotY = Math.Clamp(desiredUp.Y, -1f, 1f);
|
||||||
if (MathF.Acos(dotY) > maxDesiredTiltRad)
|
if (MathF.Acos(dotY) > maxDesiredTiltRad)
|
||||||
|
|
@ -1049,10 +1189,10 @@ namespace RustToDust.Ymir
|
||||||
|
|
||||||
float maxFoot = MathF.Max(spec.HalfWidth, spec.HalfLength);
|
float maxFoot = MathF.Max(spec.HalfWidth, spec.HalfLength);
|
||||||
float iTilt = MathF.Max(1f, (spec.HalfHeight * spec.HalfHeight + maxFoot * maxFoot) / 3f);
|
float iTilt = MathF.Max(1f, (spec.HalfHeight * spec.HalfHeight + maxFoot * maxFoot) / 3f);
|
||||||
float rightingGain = (isWalker ? 48f : 28f) * iTilt;
|
float rightingGain = 28f * iTilt;
|
||||||
float dampingGain = (isWalker ? 11f : 8.5f) * iTilt;
|
float dampingGain = 8.5f * iTilt;
|
||||||
|
|
||||||
float tiltLimitRad = isWalker ? MathF.PI / 12f : MathF.PI * 48f / 180f;
|
const float tiltLimitRad = MathF.PI * 48f / 180f;
|
||||||
float worldTiltRad = MathF.Acos(Math.Clamp(up.Y, -1f, 1f));
|
float worldTiltRad = MathF.Acos(Math.Clamp(up.Y, -1f, 1f));
|
||||||
Vector3 arrestTorque = Vector3.Zero;
|
Vector3 arrestTorque = Vector3.Zero;
|
||||||
if (worldTiltRad > tiltLimitRad)
|
if (worldTiltRad > tiltLimitRad)
|
||||||
|
|
@ -1070,11 +1210,11 @@ namespace RustToDust.Ymir
|
||||||
float angOut = Vector3.Dot(new Vector3(angVel.X, 0f, angVel.Z), uprightDir);
|
float angOut = Vector3.Dot(new Vector3(angVel.X, 0f, angVel.Z), uprightDir);
|
||||||
if (angOut < 0f)
|
if (angOut < 0f)
|
||||||
{
|
{
|
||||||
arrestTorque = uprightDir * (-angOut * mass * iTilt * (isWalker ? 28f : 18f));
|
arrestTorque = uprightDir * (-angOut * mass * iTilt * 18f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rightingGain *= 1f + (worldTiltRad - tiltLimitRad) * (isWalker ? 6f : 4f);
|
rightingGain *= 1f + (worldTiltRad - tiltLimitRad) * 4f;
|
||||||
}
|
}
|
||||||
|
|
||||||
return supportTorque + arrestTorque + tiltAxis * (mass * rightingGain) - new Vector3(angVel.X, 0f, angVel.Z) * (mass * dampingGain);
|
return supportTorque + arrestTorque + tiltAxis * (mass * rightingGain) - new Vector3(angVel.X, 0f, angVel.Z) * (mass * dampingGain);
|
||||||
|
|
@ -1111,7 +1251,6 @@ namespace RustToDust.Ymir
|
||||||
float restTravel = isSion ? 0.22f : 0.20f;
|
float restTravel = isSion ? 0.22f : 0.20f;
|
||||||
float kSpring = mass * (isSion ? 95f : 85f);
|
float kSpring = mass * (isSion ? 95f : 85f);
|
||||||
float cDamp = mass * (isSion ? 12.0f : 10.5f);
|
float cDamp = mass * (isSion ? 12.0f : 10.5f);
|
||||||
float torqueScale = spec.IsWalker ? 0.12f : 1.0f;
|
|
||||||
float maxPen = 0f;
|
float maxPen = 0f;
|
||||||
|
|
||||||
Span<Vector3> corners = stackalloc Vector3[4]
|
Span<Vector3> corners = stackalloc Vector3[4]
|
||||||
|
|
@ -1138,7 +1277,7 @@ namespace RustToDust.Ymir
|
||||||
float fN = Math.Clamp(kSpring * penEff + bumpExtra - cDamp * vCornerN, 0f, mass * (isSion ? 42f : 65f));
|
float fN = Math.Clamp(kSpring * penEff + bumpExtra - cDamp * vCornerN, 0f, mass * (isSion ? 42f : 65f));
|
||||||
Vector3 cornerForce = supportDir * fN;
|
Vector3 cornerForce = supportDir * fN;
|
||||||
supportForce += cornerForce;
|
supportForce += cornerForce;
|
||||||
supportTorque += Vector3.Cross(r, cornerForce) * torqueScale;
|
supportTorque += Vector3.Cross(r, cornerForce);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1219,6 +1358,10 @@ namespace RustToDust.Ymir
|
||||||
c.VelY = vy;
|
c.VelY = vy;
|
||||||
c.VelZ = vz;
|
c.VelZ = vz;
|
||||||
c.Speed = MathF.Sqrt(vx * vx + vz * vz);
|
c.Speed = MathF.Sqrt(vx * vx + vz * vz);
|
||||||
|
if (_contenderWalkers.TryGetValue(c.Id, out var ws))
|
||||||
|
{
|
||||||
|
ws.SyncBodyPoseOnly(new Vector3(c.X, c.Y, c.Z), Quaternion.Normalize(q), view.Mass[lane]);
|
||||||
|
}
|
||||||
|
|
||||||
float stepDist = MathF.Sqrt((c.X - prevX) * (c.X - prevX) + (c.Z - prevZ) * (c.Z - prevZ));
|
float stepDist = MathF.Sqrt((c.X - prevX) * (c.X - prevX) + (c.Z - prevZ) * (c.Z - prevZ));
|
||||||
float groundY = State.Terrain.SampleHeight(c.X, c.Z);
|
float groundY = State.Terrain.SampleHeight(c.X, c.Z);
|
||||||
|
|
@ -1255,6 +1398,10 @@ namespace RustToDust.Ymir
|
||||||
var q = new Quaternion(s.CurrRotX, s.CurrRotY, s.CurrRotZ, s.CurrRotW);
|
var q = new Quaternion(s.CurrRotX, s.CurrRotY, s.CurrRotZ, s.CurrRotW);
|
||||||
var forward = Vector3.Transform(Vector3.UnitZ, q);
|
var forward = Vector3.Transform(Vector3.UnitZ, q);
|
||||||
s.Yaw = MathF.Atan2(forward.X, forward.Z);
|
s.Yaw = MathF.Atan2(forward.X, forward.Z);
|
||||||
|
if (_spectatorWalkers.TryGetValue(s.Id, out var ws))
|
||||||
|
{
|
||||||
|
ws.SyncBodyPoseOnly(new Vector3(s.X, s.Y, s.Z), Quaternion.Normalize(q), view.Mass[lane]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1961,6 +2108,13 @@ namespace RustToDust.Ymir
|
||||||
shooterGrid.InjectHardpointHeat(mod.HardpointId, mod.Spec.HeatOutput);
|
shooterGrid.InjectHardpointHeat(mod.HardpointId, mod.Spec.HeatOutput);
|
||||||
mod.Cooldown = mod.Spec.FireCooldown;
|
mod.Cooldown = mod.Spec.FireCooldown;
|
||||||
|
|
||||||
|
if (shooterGrid.Spec.IsWalker)
|
||||||
|
{
|
||||||
|
bool isContenderShooter = !isSpectatorShooter;
|
||||||
|
int entityId = (int)(shooterStableId - (isContenderShooter ? ContenderStableIdBase : SpectatorStableIdBase));
|
||||||
|
AddWalkerRecoilImpulse(isContenderShooter, entityId, baseAim, mod.Spec.WeaponDamage);
|
||||||
|
}
|
||||||
|
|
||||||
if (shooterContender is not null)
|
if (shooterContender is not null)
|
||||||
{
|
{
|
||||||
State.LastGunfireX = shooterPos.X;
|
State.LastGunfireX = shooterPos.X;
|
||||||
|
|
@ -2092,6 +2246,7 @@ namespace RustToDust.Ymir
|
||||||
_world.RemoveBody(handle);
|
_world.RemoveBody(handle);
|
||||||
_contenderBodies.Remove(victim.Id);
|
_contenderBodies.Remove(victim.Id);
|
||||||
}
|
}
|
||||||
|
_contenderWalkers.Remove(victim.Id);
|
||||||
|
|
||||||
if (shooterContender is not null)
|
if (shooterContender is not null)
|
||||||
{
|
{
|
||||||
|
|
@ -2116,6 +2271,7 @@ namespace RustToDust.Ymir
|
||||||
_world.RemoveBody(handle);
|
_world.RemoveBody(handle);
|
||||||
_spectatorBodies.Remove(spec.Id);
|
_spectatorBodies.Remove(spec.Id);
|
||||||
}
|
}
|
||||||
|
_spectatorWalkers.Remove(spec.Id);
|
||||||
|
|
||||||
if (shooterContender is not null)
|
if (shooterContender is not null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
1576
src/RustToDust.Ymir/WalkerLocomotion.cs
Normal file
1576
src/RustToDust.Ymir/WalkerLocomotion.cs
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -252,8 +252,11 @@ namespace RustToDust.Tests
|
||||||
var other = session.State.Spectators.Spectators[i];
|
var other = session.State.Spectators.Spectators[i];
|
||||||
if (other.Id != provokedSpec.Id && other.Id != clearedSpec.Id)
|
if (other.Id != provokedSpec.Id && other.Id != clearedSpec.Id)
|
||||||
{
|
{
|
||||||
float farX = (mesa.X >= 0f ? -1f : 1f) * 680f;
|
// Space bystanders in a non-overlapping grid at the far corner so Box3D never stacks them into a tower peeking over the mesa
|
||||||
float farZ = (mesa.Z >= 0f ? -1f : 1f) * 680f;
|
float signX = mesa.X >= 0f ? -1f : 1f;
|
||||||
|
float signZ = mesa.Z >= 0f ? -1f : 1f;
|
||||||
|
float farX = signX * (730f - (i % 8) * 16f);
|
||||||
|
float farZ = signZ * (730f - (i / 8) * 16f);
|
||||||
session.SetSpectatorPose(other.Id, farX, farZ);
|
session.SetSpectatorPose(other.Id, farX, farZ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
714
tests/RustToDust.Tests/HybridBWalkerTests.cs
Normal file
714
tests/RustToDust.Tests/HybridBWalkerTests.cs
Normal file
|
|
@ -0,0 +1,714 @@
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Numerics;
|
||||||
|
using RustToDust.Core;
|
||||||
|
using RustToDust.Ymir;
|
||||||
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
|
namespace RustToDust.Tests
|
||||||
|
{
|
||||||
|
public sealed class HybridBWalkerTests
|
||||||
|
{
|
||||||
|
private readonly ITestOutputHelper _output;
|
||||||
|
|
||||||
|
public HybridBWalkerTests(ITestOutputHelper output)
|
||||||
|
{
|
||||||
|
_output = output;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ChassisSpec MakeExemplarSpec() =>
|
||||||
|
Catalog.Raptor with
|
||||||
|
{
|
||||||
|
Id = "exemplar_frame",
|
||||||
|
Name = "Exemplar Frame",
|
||||||
|
BaseCellArmor = 22f,
|
||||||
|
MassKg = 1150f,
|
||||||
|
BaseThrust = 26000f,
|
||||||
|
BaseTurnRate = 6.2f,
|
||||||
|
MaxSpeed = 40f,
|
||||||
|
HalfWidth = 0.8f,
|
||||||
|
HalfHeight = 1.55f,
|
||||||
|
HalfLength = 0.8f
|
||||||
|
};
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void HybridB_All7Mechs_WalkTurnSlopes_SmoothLiftoff_ZeroTeleports()
|
||||||
|
{
|
||||||
|
var specs = new[]
|
||||||
|
{
|
||||||
|
Catalog.Breaker,
|
||||||
|
Catalog.Paladin,
|
||||||
|
Catalog.Raptor,
|
||||||
|
Catalog.Spectre,
|
||||||
|
Catalog.Kestrel,
|
||||||
|
Catalog.Manticore,
|
||||||
|
Catalog.Bastion,
|
||||||
|
MakeExemplarSpec()
|
||||||
|
};
|
||||||
|
|
||||||
|
// 1. Walk, turn, and climb slopes across all 7 mechs + exemplar_frame
|
||||||
|
foreach (var spec in specs)
|
||||||
|
{
|
||||||
|
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert);
|
||||||
|
for (int i = 1; i < session.State.Contenders.Count; i++)
|
||||||
|
{
|
||||||
|
session.SetContenderPose(i, 500f + i * 16f, 500f);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Phase A: start on flat/gentle ground near origin (60 ticks) to verify honest walk slip < 8cm
|
||||||
|
session.SetContenderPose(0, 0f, 0f, 0f);
|
||||||
|
session.State.SpawnChassisDrop(0f, 0f, spec);
|
||||||
|
Assert.True(session.TrySwapNearbyChassis(), $"Failed swap to {spec.Id}");
|
||||||
|
var player = session.State.Player;
|
||||||
|
Assert.Equal(spec.Id, player.Grid.Spec.Id);
|
||||||
|
|
||||||
|
var ws = session.GetWalkerState(true, player.Id);
|
||||||
|
Assert.NotNull(ws);
|
||||||
|
int nLegs = ws!.Geom.LegCount;
|
||||||
|
float geomScale = ws.GeomScale;
|
||||||
|
|
||||||
|
for (int t = 0; t < 60; t++)
|
||||||
|
{
|
||||||
|
session.Step(new PlayerInput(
|
||||||
|
Throttle: 0.45f,
|
||||||
|
Steer: 0f,
|
||||||
|
AimWorldX: player.X,
|
||||||
|
AimWorldZ: player.Z + 60f,
|
||||||
|
Fire: false,
|
||||||
|
InteractPickup: false,
|
||||||
|
Brake: false));
|
||||||
|
}
|
||||||
|
Assert.True(ws.MaxFootSlipM < 0.08f,
|
||||||
|
$"{spec.Id}: normal walk foot slip {ws.MaxFootSlipM:F4}m >= 0.08m (maxSpd={spec.MaxSpeed:F1})");
|
||||||
|
|
||||||
|
// Phase B: move to dune slope approach, turn & climb (180 ticks) checking liftoff teleport, C1 touchdown, omega continuity
|
||||||
|
float duneApproachX = 0f;
|
||||||
|
float duneApproachZ = 0f;
|
||||||
|
float bestScore = -1f;
|
||||||
|
foreach (var b in session.State.Terrain.Brushes)
|
||||||
|
{
|
||||||
|
if (b.Kind == TerrainBrushKind.DuneRidge && b.HeightDelta > 4f)
|
||||||
|
{
|
||||||
|
float d = MathF.Sqrt(b.X * b.X + b.Z * b.Z);
|
||||||
|
if (d > 40f && d < 280f && b.HeightDelta > bestScore)
|
||||||
|
{
|
||||||
|
bestScore = b.HeightDelta;
|
||||||
|
float dirX = -b.X / d;
|
||||||
|
float dirZ = -b.Z / d;
|
||||||
|
duneApproachX = b.X + dirX * MathF.Min(36f, b.RadiusX * 0.85f);
|
||||||
|
duneApproachZ = b.Z + dirZ * MathF.Min(36f, b.RadiusZ * 0.85f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
session.SetContenderPose(0, duneApproachX, duneApproachZ, MathF.Atan2(-duneApproachX, -duneApproachZ) + MathF.PI);
|
||||||
|
ws = session.GetWalkerState(true, player.Id)!;
|
||||||
|
|
||||||
|
var prevFoot = new Vector3[nLegs];
|
||||||
|
var prevPlanted = new bool[nLegs];
|
||||||
|
var prevOmegaHip = new float[nLegs];
|
||||||
|
for (int i = 0; i < nLegs; i++)
|
||||||
|
{
|
||||||
|
prevFoot[i] = ws.FootSole[i];
|
||||||
|
prevPlanted[i] = ws.Planted[i];
|
||||||
|
prevOmegaHip[i] = ws.Actuators[i].Omega.HipPitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
float maxDeltaFootPerTick = 0f;
|
||||||
|
float maxLiftoffDelta = 0f;
|
||||||
|
float maxOmegaJumpAtSwap = 0f;
|
||||||
|
float maxTouchdownGroundErr = 0f;
|
||||||
|
float minUpDot = 1f;
|
||||||
|
int swapCount = 0;
|
||||||
|
for (int t = 0; t < 180; t++)
|
||||||
|
{
|
||||||
|
float steer = MathF.Sin(t * 0.06f) * 0.65f;
|
||||||
|
session.Step(new PlayerInput(
|
||||||
|
Throttle: 0.85f,
|
||||||
|
Steer: steer,
|
||||||
|
AimWorldX: player.X + 40f * MathF.Sin(player.Yaw),
|
||||||
|
AimWorldZ: player.Z + 40f * MathF.Cos(player.Yaw),
|
||||||
|
Fire: false,
|
||||||
|
InteractPickup: false,
|
||||||
|
Brake: false));
|
||||||
|
|
||||||
|
Assert.True(float.IsFinite(player.X) && float.IsFinite(player.Y) && float.IsFinite(player.Z),
|
||||||
|
$"{spec.Id}: non-finite pose at tick {t}");
|
||||||
|
|
||||||
|
var q = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
|
||||||
|
var up = Vector3.Transform(Vector3.UnitY, q);
|
||||||
|
minUpDot = MathF.Min(minUpDot, up.Y);
|
||||||
|
|
||||||
|
for (int i = 0; i < nLegs; i++)
|
||||||
|
{
|
||||||
|
Vector3 curFoot = ws.FootSole[i];
|
||||||
|
float delta = (curFoot - prevFoot[i]).Length();
|
||||||
|
if (delta > maxDeltaFootPerTick)
|
||||||
|
{
|
||||||
|
maxDeltaFootPerTick = delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool curPlanted = ws.Planted[i];
|
||||||
|
if (prevPlanted[i] && !curPlanted && !ws.IsAirborne)
|
||||||
|
{
|
||||||
|
if (delta > maxLiftoffDelta)
|
||||||
|
{
|
||||||
|
maxLiftoffDelta = delta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!prevPlanted[i] && curPlanted)
|
||||||
|
{
|
||||||
|
swapCount++;
|
||||||
|
float groundY = session.State.Terrain.SampleHeight(curFoot.X, curFoot.Z);
|
||||||
|
float gErr = MathF.Abs(curFoot.Y - groundY);
|
||||||
|
if (gErr > maxTouchdownGroundErr)
|
||||||
|
{
|
||||||
|
maxTouchdownGroundErr = gErr;
|
||||||
|
}
|
||||||
|
|
||||||
|
float omegaDelta = MathF.Abs(ws.Actuators[i].Omega.HipPitch - prevOmegaHip[i]);
|
||||||
|
if (omegaDelta > maxOmegaJumpAtSwap)
|
||||||
|
{
|
||||||
|
maxOmegaJumpAtSwap = omegaDelta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prevFoot[i] = curFoot;
|
||||||
|
prevPlanted[i] = curPlanted;
|
||||||
|
prevOmegaHip[i] = ws.Actuators[i].Omega.HipPitch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float maxFootGroundSpeed = spec.MaxSpeed + MathF.Max(spec.HalfWidth, spec.HalfLength) * spec.BaseTurnRate * 0.5f;
|
||||||
|
float maxAllowedTickDelta = MathF.Max(0.55f, maxFootGroundSpeed * ArenaSession.FixedDt * 3.5f);
|
||||||
|
_output.WriteLine(
|
||||||
|
$"{spec.Id,-15} minUp={minUpDot:F3} slip={ws.MaxFootSlipM:F4}m maxFootDelta/tick={maxDeltaFootPerTick:F4}m " +
|
||||||
|
$"liftoffDelta={maxLiftoffDelta:F4}m tdGroundErr={maxTouchdownGroundErr:F5}m swapOmegaJump={maxOmegaJumpAtSwap:F3} swaps={swapCount}");
|
||||||
|
|
||||||
|
Assert.True(minUpDot >= 0.90f, $"{spec.Id}: unstable tilt minUpDot={minUpDot:F3}");
|
||||||
|
Assert.True(swapCount >= 4, $"{spec.Id}: expected >= 4 gait transitions, got {swapCount}");
|
||||||
|
Assert.True(maxLiftoffDelta <= 0.35f * MathF.Max(1f, geomScale),
|
||||||
|
$"{spec.Id}: Bug 1 liftoff teleport detected: liftoffDelta={maxLiftoffDelta:F4}m");
|
||||||
|
Assert.True(maxDeltaFootPerTick <= maxAllowedTickDelta,
|
||||||
|
$"{spec.Id}: 1-tick foot teleport detected: maxDelta={maxDeltaFootPerTick:F4}m > {maxAllowedTickDelta:F4}m");
|
||||||
|
Assert.True(maxTouchdownGroundErr <= 0.06f * MathF.Max(1f, geomScale),
|
||||||
|
$"{spec.Id}: non-C1 liftoff/touchdown height gap {maxTouchdownGroundErr:F4}m");
|
||||||
|
Assert.True(maxOmegaJumpAtSwap < 12.0f,
|
||||||
|
$"{spec.Id}: discontinuous joint omega jump across swap: {maxOmegaJumpAtSwap:F3} rad/s");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Benchmark 12 simultaneous mechs CPU < 1.5 ms/tick
|
||||||
|
{
|
||||||
|
using var benchSession = new ArenaSession(seed: 99, mapKind: ArenaMapKind.Desert);
|
||||||
|
for (int i = 0; i < benchSession.State.Contenders.Count; i++)
|
||||||
|
{
|
||||||
|
var spec = specs[i % 7];
|
||||||
|
float x = (i - 5.5f) * 28f;
|
||||||
|
float z = -80f + (i % 3) * 35f;
|
||||||
|
benchSession.SetContenderPose(i, x, z, 0f);
|
||||||
|
if (benchSession.State.Contenders[i].Grid.Spec.Id != spec.Id)
|
||||||
|
{
|
||||||
|
benchSession.State.Contenders[i].Grid.SwapChassis(spec);
|
||||||
|
benchSession.SetContenderPose(i, x, z, 0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var walkers = new (ContenderState C, WalkerState Ws, int Lane)[12];
|
||||||
|
for (int i = 0; i < 12; i++)
|
||||||
|
{
|
||||||
|
var c = benchSession.State.Contenders[i];
|
||||||
|
c.ThrottleCmd = 0.8f;
|
||||||
|
c.SteerCmd = (i % 2 == 0 ? 0.2f : -0.2f);
|
||||||
|
walkers[i] = (c, benchSession.GetWalkerState(true, c.Id)!, benchSession.GetContenderBody(c.Id)!.Value.Lane);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warmup JIT
|
||||||
|
for (int w = 0; w < 20; w++)
|
||||||
|
{
|
||||||
|
benchSession.Step(new PlayerInput(0.8f, 0.2f, 0f, 100f, false, false, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
var view = benchSession.World.View;
|
||||||
|
const int benchTicks = 300;
|
||||||
|
long t0 = Stopwatch.GetTimestamp();
|
||||||
|
for (int t = 0; t < benchTicks; t++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 12; i++)
|
||||||
|
{
|
||||||
|
var (c, ws, lane) = walkers[i];
|
||||||
|
var pos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
|
||||||
|
var q = new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]);
|
||||||
|
var vel = new Vector3(view.VelocityX[lane], view.VelocityY[lane], view.VelocityZ[lane]);
|
||||||
|
var angVel = new Vector3(view.AngularVelocityX[lane], view.AngularVelocityY[lane], view.AngularVelocityZ[lane]);
|
||||||
|
var fwd = Vector3.Transform(Vector3.UnitZ, q);
|
||||||
|
fwd.Y = 0f;
|
||||||
|
fwd = fwd.LengthSquared() < 1e-4f ? Vector3.UnitZ : Vector3.Normalize(fwd);
|
||||||
|
WalkerLocomotion.StepWalker(
|
||||||
|
ws, c.Grid, benchSession.State.Terrain, view, lane, view.Mass[lane],
|
||||||
|
pos, q, vel, angVel, fwd * (c.ThrottleCmd * c.Grid.Spec.MaxSpeed), 0.3f, false, ArenaSession.FixedDt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
long t1 = Stopwatch.GetTimestamp();
|
||||||
|
double msPerTick = (t1 - t0) * 1000.0 / Stopwatch.Frequency / benchTicks;
|
||||||
|
_output.WriteLine($"12-mech simultaneous WalkerLocomotion CPU: {msPerTick:F4} ms/tick");
|
||||||
|
Assert.True(msPerTick < 1.5, $"12 simultaneous mechs CPU {msPerTick:F4} ms/tick exceeded 1.5 ms/tick budget");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void HybridB_CrippledLeg_ReducesGrfAndTorque_InducesLimp()
|
||||||
|
{
|
||||||
|
Span<float> legIntegrities = stackalloc float[4];
|
||||||
|
foreach (var spec in new[] { Catalog.Breaker, Catalog.Bastion })
|
||||||
|
{
|
||||||
|
using var session = new ArenaSession(seed: 17, mapKind: ArenaMapKind.Desert);
|
||||||
|
for (int i = 1; i < session.State.Contenders.Count; i++)
|
||||||
|
{
|
||||||
|
session.SetContenderPose(i, 450f + i * 16f, 450f);
|
||||||
|
}
|
||||||
|
session.SetContenderPose(0, 0f, 0f, 0f);
|
||||||
|
session.State.SpawnChassisDrop(0f, 0f, spec);
|
||||||
|
Assert.True(session.TrySwapNearbyChassis());
|
||||||
|
|
||||||
|
var player = session.State.Player;
|
||||||
|
var grid = player.Grid;
|
||||||
|
|
||||||
|
// Strip all left-leg cells (Breaker Coronal L: y>=H-2, x<W/2; Bastion Dorsal FL: y<H/2, x<W/2)
|
||||||
|
if (spec.Plane == GridPlane.Coronal)
|
||||||
|
{
|
||||||
|
for (int y = spec.Height - 2; y < spec.Height; y++)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < spec.Width / 2; x++)
|
||||||
|
{
|
||||||
|
grid.Armor[x, y] = 0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int y = 0; y < spec.Height / 2; y++)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < spec.Width / 2; x++)
|
||||||
|
{
|
||||||
|
grid.Armor[x, y] = 0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
legIntegrities.Clear();
|
||||||
|
grid.GetLegIntegrities(legIntegrities);
|
||||||
|
Assert.Equal(0.25f, legIntegrities[0], precision: 3);
|
||||||
|
Assert.Equal(1.00f, legIntegrities[1], precision: 3);
|
||||||
|
Assert.True(grid.LegIntegrity < 1.0f, $"Expected {spec.Id} LegIntegrity < 1.0 after leg strip");
|
||||||
|
|
||||||
|
var ws = session.GetWalkerState(true, player.Id)!;
|
||||||
|
float peakLeftGrf = 0f;
|
||||||
|
float peakRightGrf = 0f;
|
||||||
|
float maxRollAbs = 0f;
|
||||||
|
float maxOmegaLeft = 0f;
|
||||||
|
float maxOmegaRight = 0f;
|
||||||
|
|
||||||
|
for (int t = 0; t < 180; t++)
|
||||||
|
{
|
||||||
|
session.Step(new PlayerInput(
|
||||||
|
Throttle: 0.9f,
|
||||||
|
Steer: 0f,
|
||||||
|
AimWorldX: player.X,
|
||||||
|
AimWorldZ: player.Z + 80f,
|
||||||
|
Fire: false,
|
||||||
|
InteractPickup: false,
|
||||||
|
Brake: false));
|
||||||
|
|
||||||
|
Assert.True(float.IsFinite(player.X) && float.IsFinite(player.Y) && float.IsFinite(player.Z));
|
||||||
|
peakLeftGrf = MathF.Max(peakLeftGrf, ws.LastGrfY[0]);
|
||||||
|
peakRightGrf = MathF.Max(peakRightGrf, ws.LastGrfY[1]);
|
||||||
|
maxOmegaLeft = MathF.Max(maxOmegaLeft, MathF.Abs(ws.Actuators[0].Omega.HipPitch));
|
||||||
|
maxOmegaRight = MathF.Max(maxOmegaRight, MathF.Abs(ws.Actuators[1].Omega.HipPitch));
|
||||||
|
|
||||||
|
var q = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
|
||||||
|
var rightVec = Vector3.Transform(Vector3.UnitX, q);
|
||||||
|
maxRollAbs = MathF.Max(maxRollAbs, MathF.Abs(rightVec.Y));
|
||||||
|
}
|
||||||
|
|
||||||
|
_output.WriteLine(
|
||||||
|
$"{spec.Id} crippled left leg: peakLeftGrf={peakLeftGrf:F1}N peakRightGrf={peakRightGrf:F1}N " +
|
||||||
|
$"maxRollSin={maxRollAbs:F4} omegaL={maxOmegaLeft:F2} omegaR={maxOmegaRight:F2}");
|
||||||
|
|
||||||
|
Assert.True(peakLeftGrf < peakRightGrf * 0.55f,
|
||||||
|
$"{spec.Id}: expected crippled left GRF ({peakLeftGrf:F1}N) << healthy right GRF ({peakRightGrf:F1}N)");
|
||||||
|
Assert.True(maxRollAbs > 0.002f,
|
||||||
|
$"{spec.Id}: expected crippled leg asymmetry to induce measurable limp roll");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void HybridB_AirborneMech_ZeroGrfForce()
|
||||||
|
{
|
||||||
|
foreach (var spec in new[] { Catalog.Breaker, Catalog.Manticore })
|
||||||
|
{
|
||||||
|
using var session = new ArenaSession(seed: 7, mapKind: ArenaMapKind.Desert);
|
||||||
|
session.SetContenderPose(0, 0f, 0f, 0f);
|
||||||
|
session.State.SpawnChassisDrop(0f, 0f, spec);
|
||||||
|
Assert.True(session.TrySwapNearbyChassis());
|
||||||
|
|
||||||
|
var player = session.State.Player;
|
||||||
|
var body = session.GetContenderBody(player.Id)!.Value;
|
||||||
|
var view = session.World.View;
|
||||||
|
int lane = body.Lane;
|
||||||
|
|
||||||
|
// 1. Direct StepWalker check with COM lifted 18m above terrain
|
||||||
|
float groundY = session.State.Terrain.SampleHeight(0f, 0f);
|
||||||
|
Vector3 liftedPos = new(view.PositionX[lane], groundY + spec.HalfHeight + 18f, view.PositionZ[lane]);
|
||||||
|
|
||||||
|
var ws = session.GetWalkerState(true, player.Id)!;
|
||||||
|
WalkerLocomotion.StepWalker(
|
||||||
|
ws,
|
||||||
|
player.Grid,
|
||||||
|
session.State.Terrain,
|
||||||
|
view,
|
||||||
|
lane,
|
||||||
|
view.Mass[lane],
|
||||||
|
liftedPos,
|
||||||
|
new Quaternion(view.RotationX[lane], view.RotationY[lane], view.RotationZ[lane], view.RotationW[lane]),
|
||||||
|
Vector3.Zero,
|
||||||
|
Vector3.Zero,
|
||||||
|
new Vector3(0f, 0f, 10f),
|
||||||
|
0f,
|
||||||
|
false,
|
||||||
|
ArenaSession.FixedDt);
|
||||||
|
|
||||||
|
Assert.True(ws.IsAirborne, $"{spec.Id}: expected IsAirborne == true when lifted 18m above terrain");
|
||||||
|
Assert.Equal(Vector3.Zero, ws.LastTotalForce);
|
||||||
|
Assert.Equal(Vector3.Zero, ws.LastTotalTorque);
|
||||||
|
Assert.Equal(0f, view.ForceX[lane]);
|
||||||
|
Assert.Equal(0f, view.ForceY[lane]);
|
||||||
|
Assert.Equal(0f, view.ForceZ[lane]);
|
||||||
|
Assert.Equal(0f, view.TorqueX[lane]);
|
||||||
|
Assert.Equal(0f, view.TorqueY[lane]);
|
||||||
|
Assert.Equal(0f, view.TorqueZ[lane]);
|
||||||
|
|
||||||
|
// 2. End-to-end ArenaSession launch into air: confirm zero GRF while airborne in real Step()
|
||||||
|
session.World.ApplyImpulse(
|
||||||
|
lane,
|
||||||
|
(0f, view.Mass[lane] * 28f, 0f),
|
||||||
|
(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]));
|
||||||
|
bool sawAirborneTick = false;
|
||||||
|
for (int t = 0; t < 20; t++)
|
||||||
|
{
|
||||||
|
session.Step(new PlayerInput(1f, 0f, 0f, 50f, false, false, false));
|
||||||
|
if (ws.IsAirborne)
|
||||||
|
{
|
||||||
|
sawAirborneTick = true;
|
||||||
|
Assert.Equal(Vector3.Zero, ws.LastTotalForce);
|
||||||
|
Assert.Equal(Vector3.Zero, ws.LastTotalTorque);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Assert.True(sawAirborneTick, $"{spec.Id}: expected vertical launch to trigger airborne zero-GRF ticks");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void HybridB_All7Mechs_ObeyDirectionalInputAtMultipleYaws_NoGooseStepNoDrift()
|
||||||
|
{
|
||||||
|
var specs = new[]
|
||||||
|
{
|
||||||
|
Catalog.Breaker,
|
||||||
|
Catalog.Paladin,
|
||||||
|
Catalog.Raptor,
|
||||||
|
Catalog.Spectre,
|
||||||
|
Catalog.Kestrel,
|
||||||
|
Catalog.Manticore,
|
||||||
|
Catalog.Bastion
|
||||||
|
};
|
||||||
|
float[] yawsDeg = { 0f, 45f, 90f, 135f };
|
||||||
|
|
||||||
|
foreach (var spec in specs)
|
||||||
|
{
|
||||||
|
foreach (float yawDeg in yawsDeg)
|
||||||
|
{
|
||||||
|
float yawRad = yawDeg * MathF.PI / 180f;
|
||||||
|
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Desert);
|
||||||
|
for (int i = 1; i < session.State.Contenders.Count; i++)
|
||||||
|
{
|
||||||
|
session.SetContenderPose(i, 500f + i * 16f, 500f);
|
||||||
|
}
|
||||||
|
|
||||||
|
session.SetContenderPose(0, 0f, 0f, yawRad);
|
||||||
|
session.State.SpawnChassisDrop(0f, 0f, spec);
|
||||||
|
Assert.True(session.TrySwapNearbyChassis(), $"Failed swap to {spec.Id}");
|
||||||
|
session.SetContenderPose(0, 0f, 0f, yawRad);
|
||||||
|
var player = session.State.Player;
|
||||||
|
|
||||||
|
// Lettle -> Wait 5 idle ticks to verify zero rest creep from dead stop
|
||||||
|
for (int t = 0; t < 5; t++)
|
||||||
|
{
|
||||||
|
session.Step(new PlayerInput(0f, 0f, player.X, player.Z + 50f, false, false, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2 cmdFwd = new(MathF.Sin(yawRad), MathF.Cos(yawRad));
|
||||||
|
Vector2 cmdRight = new(-cmdFwd.Y, cmdFwd.X);
|
||||||
|
|
||||||
|
// 1. Hold W (Throttle = +1) for 2.0s (120 ticks) from rest
|
||||||
|
Vector2 wStart = new(player.X, player.Z);
|
||||||
|
for (int t = 0; t < 120; t++)
|
||||||
|
{
|
||||||
|
session.Step(new PlayerInput(
|
||||||
|
Throttle: 1f,
|
||||||
|
Steer: 0f,
|
||||||
|
AimWorldX: player.X + cmdFwd.X * 50f,
|
||||||
|
AimWorldZ: player.Z + cmdFwd.Y * 50f,
|
||||||
|
Fire: false,
|
||||||
|
InteractPickup: false,
|
||||||
|
Brake: false));
|
||||||
|
}
|
||||||
|
float endWSpeed = player.Speed;
|
||||||
|
Vector2 wDelta = new Vector2(player.X, player.Z) - wStart;
|
||||||
|
float fwdDisp = Vector2.Dot(wDelta, cmdFwd);
|
||||||
|
float latDrift = MathF.Abs(Vector2.Dot(wDelta, cmdRight));
|
||||||
|
Assert.True(fwdDisp >= 6.0f,
|
||||||
|
$"{spec.Id} @ {yawDeg}deg W 2.0s: fwdDisp={fwdDisp:F2}m < 6.0m (lat={latDrift:F2}m)");
|
||||||
|
Assert.True(latDrift < 2.0f,
|
||||||
|
$"{spec.Id} @ {yawDeg}deg W 2.0s: latDrift={latDrift:F2}m >= 2.0m (fwd={fwdDisp:F2}m)");
|
||||||
|
|
||||||
|
// 2. Release W (Throttle = 0) for 3.0s (180 ticks): stop < 0.30 m/s within physical Coulomb limit, final 1.0s (60 ticks) drift < 0.15m
|
||||||
|
float speedAt1_2s = 0f;
|
||||||
|
float speedAt2_0s = 0f;
|
||||||
|
float timeToStop = -1f;
|
||||||
|
Vector2 finalWindowStart = Vector2.Zero;
|
||||||
|
for (int t = 0; t < 180; t++)
|
||||||
|
{
|
||||||
|
session.Step(new PlayerInput(
|
||||||
|
Throttle: 0f,
|
||||||
|
Steer: 0f,
|
||||||
|
AimWorldX: player.X + cmdFwd.X * 50f,
|
||||||
|
AimWorldZ: player.Z + cmdFwd.Y * 50f,
|
||||||
|
Fire: false,
|
||||||
|
InteractPickup: false,
|
||||||
|
Brake: false));
|
||||||
|
|
||||||
|
if (timeToStop < 0f && player.Speed < 0.30f)
|
||||||
|
{
|
||||||
|
timeToStop = (t + 1) * ArenaSession.FixedDt;
|
||||||
|
}
|
||||||
|
if (t == 71) speedAt1_2s = player.Speed;
|
||||||
|
if (t == 119)
|
||||||
|
{
|
||||||
|
speedAt2_0s = player.Speed;
|
||||||
|
finalWindowStart = new Vector2(player.X, player.Z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
float finalDrift = (new Vector2(player.X, player.Z) - finalWindowStart).Length();
|
||||||
|
float maxPhysStopSec = MathF.Max(1.2f, endWSpeed / 16.0f + 0.35f);
|
||||||
|
if (yawDeg == 0f)
|
||||||
|
{
|
||||||
|
_output.WriteLine(
|
||||||
|
$"{spec.Id,-10} maxSpd={spec.MaxSpeed:F1} endWSpd={endWSpeed:F2} " +
|
||||||
|
$"tStop={timeToStop:F2}s (limit={maxPhysStopSec:F2}s) spd@1.2s={speedAt1_2s:F3} spd@2.0s={speedAt2_0s:F3} finalDrift={finalDrift:F4}m");
|
||||||
|
}
|
||||||
|
Assert.True(timeToStop > 0f && timeToStop <= maxPhysStopSec,
|
||||||
|
$"{spec.Id} @ {yawDeg}deg release W: tStop={timeToStop:F2}s > {maxPhysStopSec:F2}s (endWSpd={endWSpeed:F2}, @2.0s={speedAt2_0s:F3})");
|
||||||
|
Assert.True(finalDrift < 0.15f,
|
||||||
|
$"{spec.Id} @ {yawDeg}deg release W: final 1.0s drift={finalDrift:F4}m >= 0.15m");
|
||||||
|
|
||||||
|
// 3. Hold S (Throttle = -1) for 1.5s (90 ticks)
|
||||||
|
Vector2 sStart = new(player.X, player.Z);
|
||||||
|
Vector2 revDir = new(MathF.Sin(player.Yaw), MathF.Cos(player.Yaw));
|
||||||
|
for (int t = 0; t < 90; t++)
|
||||||
|
{
|
||||||
|
session.Step(new PlayerInput(
|
||||||
|
Throttle: -1f,
|
||||||
|
Steer: 0f,
|
||||||
|
AimWorldX: player.X + revDir.X * 50f,
|
||||||
|
AimWorldZ: player.Z + revDir.Y * 50f,
|
||||||
|
Fire: false,
|
||||||
|
InteractPickup: false,
|
||||||
|
Brake: false));
|
||||||
|
}
|
||||||
|
float revDisp = Vector2.Dot(new Vector2(player.X, player.Z) - sStart, -revDir);
|
||||||
|
Assert.True(revDisp >= 3.0f,
|
||||||
|
$"{spec.Id} @ {yawDeg}deg S 1.5s: revDisp={revDisp:F2}m < 3.0m");
|
||||||
|
|
||||||
|
// Settle until stopped before turning test
|
||||||
|
for (int t = 0; t < 180 && (t < 20 || player.Speed > 0.05f); t++)
|
||||||
|
{
|
||||||
|
session.Step(new PlayerInput(0f, 0f, player.X, player.Z + 50f, false, false, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Hold D (Steer = +1, Throttle = 0) for 1.5s (90 ticks)
|
||||||
|
Vector2 dStart = new(player.X, player.Z);
|
||||||
|
float prevYaw = player.Yaw;
|
||||||
|
float accumYaw = 0f;
|
||||||
|
for (int t = 0; t < 90; t++)
|
||||||
|
{
|
||||||
|
session.Step(new PlayerInput(
|
||||||
|
Throttle: 0f,
|
||||||
|
Steer: 1f,
|
||||||
|
AimWorldX: player.X,
|
||||||
|
AimWorldZ: player.Z + 50f,
|
||||||
|
Fire: false,
|
||||||
|
InteractPickup: false,
|
||||||
|
Brake: false));
|
||||||
|
accumYaw += MatchRules.NormalizeAngle(player.Yaw - prevYaw);
|
||||||
|
prevYaw = player.Yaw;
|
||||||
|
}
|
||||||
|
float dTrans = (new Vector2(player.X, player.Z) - dStart).Length();
|
||||||
|
// Steer = +1 turns right -> negative yaw change (-accumYaw >= 0.5 rad)
|
||||||
|
Assert.True(-accumYaw >= 0.5f,
|
||||||
|
$"{spec.Id} @ {yawDeg}deg D 1.5s: yawChange={accumYaw:F3} rad (expected <= -0.50 rad)");
|
||||||
|
Assert.True(dTrans < 1.0f,
|
||||||
|
$"{spec.Id} @ {yawDeg}deg D 1.5s: spurious translation={dTrans:F3}m >= 1.0m");
|
||||||
|
|
||||||
|
if (yawDeg == 0f || yawDeg == 135f)
|
||||||
|
{
|
||||||
|
_output.WriteLine(
|
||||||
|
$"{spec.Id,-10} yaw={yawDeg,3:F0}deg: fwd={fwdDisp:F2}m lat={latDrift:F2}m " +
|
||||||
|
$"stopSpd={speedAt1_2s:F3}m/s drift={finalDrift:F4}m rev={revDisp:F2}m turn={-accumYaw:F2}rad dTrans={dTrans:F3}m");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void HybridB_BreakerAndBastion_SionSlopeControl_ObeysInput()
|
||||||
|
{
|
||||||
|
foreach (var spec in new[] { Catalog.Breaker, Catalog.Bastion })
|
||||||
|
{
|
||||||
|
using var session = new ArenaSession(seed: 42, mapKind: ArenaMapKind.Sion);
|
||||||
|
for (int i = 1; i < session.State.Contenders.Count; i++)
|
||||||
|
{
|
||||||
|
session.SetContenderPose(i, 900f + i * 16f, 900f);
|
||||||
|
}
|
||||||
|
|
||||||
|
var sion = session.State.SionMap!;
|
||||||
|
// Find a clear sloped hillside on Sion (slope ~7-18 deg, free of buildings and low wall meshes along a +/-7m corridor)
|
||||||
|
float slopeX = session.State.Player.X;
|
||||||
|
float slopeZ = session.State.Player.Z;
|
||||||
|
float slopeYaw = 0f;
|
||||||
|
bool foundSlope = false;
|
||||||
|
for (float r = 40f; r <= 560f && !foundSlope; r += 20f)
|
||||||
|
{
|
||||||
|
for (int a = 0; a < 36 && !foundSlope; a++)
|
||||||
|
{
|
||||||
|
float ang = a * (MathF.Tau / 36f);
|
||||||
|
float x = MathF.Cos(ang) * r;
|
||||||
|
float z = MathF.Sin(ang) * r;
|
||||||
|
if (sion.IsInsideAnyBuildingXz(x, z, 14f)) continue;
|
||||||
|
var (nx, ny, nz) = session.State.Terrain.SampleNormal(x, z);
|
||||||
|
if (ny <= 0.992f && ny >= 0.950f)
|
||||||
|
{
|
||||||
|
float yaw = MathF.Atan2(-nx, -nz); // uphill heading
|
||||||
|
float fx = MathF.Sin(yaw);
|
||||||
|
float fz = MathF.Cos(yaw);
|
||||||
|
float rx = -fz;
|
||||||
|
float rz = fx;
|
||||||
|
bool clear = true;
|
||||||
|
foreach (float lat in new[] { -7f, 0f, 7f })
|
||||||
|
{
|
||||||
|
float sx = x + rx * lat;
|
||||||
|
float sz = z + rz * lat;
|
||||||
|
for (float d = 0f; d < 28f; d += 4f)
|
||||||
|
{
|
||||||
|
float ax = sx + fx * d;
|
||||||
|
float az = sz + fz * d;
|
||||||
|
float bx = sx + fx * (d + 4f);
|
||||||
|
float bz = sz + fz * (d + 4f);
|
||||||
|
if (sion.IsInsideAnyBuildingXz(ax, az, 4f) ||
|
||||||
|
session.State.Terrain.SampleNormal(ax, az).Ny < 0.90f)
|
||||||
|
{
|
||||||
|
clear = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
float gyA = session.State.Terrain.SampleHeight(ax, az);
|
||||||
|
float gyB = session.State.Terrain.SampleHeight(bx, bz);
|
||||||
|
if (!session.HasLineOfSight(ax, gyA + 2.5f, az, bx, gyB + 2.5f, bz))
|
||||||
|
{
|
||||||
|
clear = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!clear) break;
|
||||||
|
}
|
||||||
|
if (clear)
|
||||||
|
{
|
||||||
|
slopeX = x;
|
||||||
|
slopeZ = z;
|
||||||
|
slopeYaw = yaw;
|
||||||
|
foundSlope = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Assert.True(foundSlope, $"{spec.Id}: failed to locate clear Sion slope test site");
|
||||||
|
|
||||||
|
session.SetContenderPose(0, slopeX, slopeZ, slopeYaw);
|
||||||
|
session.State.SpawnChassisDrop(slopeX, slopeZ, spec);
|
||||||
|
Assert.True(session.TrySwapNearbyChassis(), $"Failed swap to {spec.Id} on Sion");
|
||||||
|
session.SetContenderPose(0, slopeX, slopeZ, slopeYaw);
|
||||||
|
var player = session.State.Player;
|
||||||
|
|
||||||
|
// 1. Drive forward up/along slope (2.0s)
|
||||||
|
Vector2 startPos = new(player.X, player.Z);
|
||||||
|
Vector2 fwdDir = new(MathF.Sin(slopeYaw), MathF.Cos(slopeYaw));
|
||||||
|
var ws = session.GetWalkerState(true, player.Id)!;
|
||||||
|
float gStart = session.State.Terrain.SampleHeight(player.X, player.Z);
|
||||||
|
float startY = player.Y;
|
||||||
|
for (int t = 0; t < 120; t++)
|
||||||
|
{
|
||||||
|
session.Step(new PlayerInput(
|
||||||
|
Throttle: 1f,
|
||||||
|
Steer: 0f,
|
||||||
|
AimWorldX: player.X + fwdDir.X * 50f,
|
||||||
|
AimWorldZ: player.Z + fwdDir.Y * 50f,
|
||||||
|
Fire: false,
|
||||||
|
InteractPickup: false,
|
||||||
|
Brake: false));
|
||||||
|
}
|
||||||
|
float gEnd = session.State.Terrain.SampleHeight(player.X, player.Z);
|
||||||
|
float fwdDisp = Vector2.Dot(new Vector2(player.X, player.Z) - startPos, fwdDir);
|
||||||
|
int pLane = session.GetContenderBody(player.Id)!.Value.Lane;
|
||||||
|
string touchesStr = "";
|
||||||
|
foreach (var tc in session.World.Facts.Touching)
|
||||||
|
{
|
||||||
|
if (tc.LaneA == pLane || tc.LaneB == pLane)
|
||||||
|
{
|
||||||
|
ulong other = tc.LaneA == pLane ? tc.StableIdB : tc.StableIdA;
|
||||||
|
touchesStr += $"{other},";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_output.WriteLine(
|
||||||
|
$"{spec.Id} Sion slope ({slopeX:F1},{slopeZ:F1}) gStart={gStart:F2} startY={startY:F2} (H={spec.HalfHeight:F2}) -> " +
|
||||||
|
$"({player.X:F1},{player.Y:F2},{player.Z:F1}) gEnd={gEnd:F2} pYaw={player.Yaw:F2} fwdDisp={fwdDisp:F2}m air={ws.IsAirborne} force={ws.LastTotalForce} touching=[{touchesStr}]");
|
||||||
|
Assert.True(fwdDisp >= 5.0f, $"{spec.Id} Sion slope W 2.0s: fwdDisp={fwdDisp:F2}m < 5.0m");
|
||||||
|
|
||||||
|
// 2. Turn cleanly on Sion slope (D for 1.5s)
|
||||||
|
float prevYaw = player.Yaw;
|
||||||
|
float accumYaw = 0f;
|
||||||
|
for (int t = 0; t < 90; t++)
|
||||||
|
{
|
||||||
|
session.Step(new PlayerInput(0f, 1f, player.X, player.Z + 50f, false, false, false));
|
||||||
|
accumYaw += MatchRules.NormalizeAngle(player.Yaw - prevYaw);
|
||||||
|
prevYaw = player.Yaw;
|
||||||
|
}
|
||||||
|
Assert.True(-accumYaw >= 0.35f, $"{spec.Id} Sion slope D 1.5s: yawChange={accumYaw:F3} rad");
|
||||||
|
|
||||||
|
// 3. Release controls on slope (3.0s): must stop cleanly and NOT slide away
|
||||||
|
float speedAt1_2s = 0f;
|
||||||
|
float timeToStop = -1f;
|
||||||
|
Vector2 finalWinStart = Vector2.Zero;
|
||||||
|
for (int t = 0; t < 180; t++)
|
||||||
|
{
|
||||||
|
session.Step(new PlayerInput(0f, 0f, player.X, player.Z + 50f, false, false, false));
|
||||||
|
if (timeToStop < 0f && player.Speed < 0.35f) timeToStop = (t + 1) * ArenaSession.FixedDt;
|
||||||
|
if (t == 71) speedAt1_2s = player.Speed;
|
||||||
|
if (t == 119) finalWinStart = new Vector2(player.X, player.Z);
|
||||||
|
}
|
||||||
|
float finalSlide = (new Vector2(player.X, player.Z) - finalWinStart).Length();
|
||||||
|
_output.WriteLine(
|
||||||
|
$"{spec.Id,-10} Sion slope ({slopeX:F1},{slopeZ:F1}): fwd={fwdDisp:F2}m turn={-accumYaw:F2}rad " +
|
||||||
|
$"tStop={timeToStop:F2}s spd@1.2s={speedAt1_2s:F3}m/s slopeSlide={finalSlide:F4}m");
|
||||||
|
Assert.True(timeToStop > 0f && timeToStop <= 2.0f, $"{spec.Id} Sion slope release: tStop={timeToStop:F2}s > 2.0s (spd@1.2s={speedAt1_2s:F3}m/s)");
|
||||||
|
Assert.True(finalSlide < 0.18f, $"{spec.Id} Sion slope release: 1.0s slide={finalSlide:F4}m >= 0.18m");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue