cut11b: smooth liftoff transition and fix world hip/idle pred in tests
This commit is contained in:
parent
bc6ec55e43
commit
6c12a79090
3 changed files with 29 additions and 14 deletions
|
|
@ -1483,7 +1483,7 @@ namespace RustToDust.Ymir
|
|||
{
|
||||
Vector3 curPelvisShift = Vector3.Transform(ws.PelvisOffset, qYaw);
|
||||
Quaternion curQTotal = Quaternion.Normalize(qYaw * Quaternion.CreateFromYawPitchRoll(0f, ws.LeanPitch, ws.LeanRoll));
|
||||
float breakFrac = n == 4 ? 0.945f : 0.955f;
|
||||
float breakFrac = n == 4 ? 0.940f : 0.945f;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if (!ws.Planted[i]) continue;
|
||||
|
|
@ -1497,6 +1497,7 @@ namespace RustToDust.Ymir
|
|||
}
|
||||
}
|
||||
|
||||
bool p0 = ws.Planted[0], p1 = ws.Planted[1], p2 = ws.Planted[2], p3 = ws.Planted[3];
|
||||
float u = earlyBreak ? 1.0f : ws.SwingPhase;
|
||||
|
||||
if (u >= 1.0f)
|
||||
|
|
@ -1610,6 +1611,13 @@ namespace RustToDust.Ymir
|
|||
continue;
|
||||
}
|
||||
|
||||
bool justLifted = i switch { 0 => p0, 1 => p1, 2 => p2, _ => p3 };
|
||||
float legUSwing = justLifted
|
||||
? MathF.Min(uSwing, 0.45f * dt / MathF.Max(0.16f, effectiveDur * (1f - overlap)))
|
||||
: uSwing;
|
||||
float legS = justLifted ? legUSwing * legUSwing * (3f - 2f * legUSwing) : s;
|
||||
float legEnv = justLifted ? MathF.Sin(MathF.PI * legUSwing) : env;
|
||||
|
||||
Vector3 hipYawW = comPos + Vector3.Transform(geom.Legs[i].HipInCom * scale, qYaw);
|
||||
Vector3 rHip = hipYawW - comPos;
|
||||
Vector3 vHip = vel + Vector3.Cross(new Vector3(0f, angVelY, 0f), rHip);
|
||||
|
|
@ -1662,8 +1670,8 @@ namespace RustToDust.Ymir
|
|||
|
||||
Vector3 predHip = predCom + new Vector3(0f, -crouchBias, 0f) + Vector3.Transform(geom.Legs[i].HipInCom * scale, predYaw);
|
||||
Vector3 curHip = comPos + new Vector3(0f, -crouchBias, 0f) + Vector3.Transform(geom.Legs[i].HipInCom * scale, qYaw);
|
||||
Vector3 reachHip = Vector3.Lerp(predHip, curHip, uSwing);
|
||||
Vector3 reachCenter = Vector3.Lerp(predCom, comPos, uSwing);
|
||||
Vector3 reachHip = Vector3.Lerp(predHip, curHip, legUSwing);
|
||||
Vector3 reachCenter = Vector3.Lerp(predCom, comPos, legUSwing);
|
||||
var tgtHit = SampleGroundAt(terrain, world, tx, tz, comPos.Y + 0.8f);
|
||||
Vector3 tgtSole = new(tx, tgtHit.SurfaceY, tz);
|
||||
if (ClampSoleToReach(reachHip, geom.Legs[i].AnkleH * scale, geom.Legs[i].MaxLegReach * scale * 0.965f, reachCenter, terrain, world, comPos.Y + 0.8f, ref tgtSole, out Vector3 tgtNorm))
|
||||
|
|
@ -1677,17 +1685,17 @@ namespace RustToDust.Ymir
|
|||
ws.SwingTargetNormal[i] = tgtHit.Normal;
|
||||
}
|
||||
|
||||
float sx = ws.SwingStartSole[i].X + (ws.SwingTargetSole[i].X - ws.SwingStartSole[i].X) * s;
|
||||
float sz = ws.SwingStartSole[i].Z + (ws.SwingTargetSole[i].Z - ws.SwingStartSole[i].Z) * s;
|
||||
float syBase = ws.SwingStartSole[i].Y + (ws.SwingTargetSole[i].Y - ws.SwingStartSole[i].Y) * s;
|
||||
float sx = ws.SwingStartSole[i].X + (ws.SwingTargetSole[i].X - ws.SwingStartSole[i].X) * legS;
|
||||
float sz = ws.SwingStartSole[i].Z + (ws.SwingTargetSole[i].Z - ws.SwingStartSole[i].Z) * legS;
|
||||
float syBase = ws.SwingStartSole[i].Y + (ws.SwingTargetSole[i].Y - ws.SwingStartSole[i].Y) * legS;
|
||||
float stepDiff = MathF.Min(MathF.Abs(ws.SwingTargetSole[i].Y - ws.SwingStartSole[i].Y), 1.0f * scale);
|
||||
float arcScale = Math.Clamp(1.05f - 0.33f * (geom.MeanHipSpan / MathF.Max(0.5f, geom.ModelRideHeight)), 0.65f, 0.85f);
|
||||
float arcLift = (geom.SwingArcHeight * scale * arcScale + 0.12f * stepDiff) * MathF.Pow(env, 1.40f);
|
||||
float arcLift = (geom.SwingArcHeight * scale * arcScale + 0.12f * stepDiff) * MathF.Pow(legEnv, 1.40f);
|
||||
var underHit = SampleGroundAt(terrain, world, sx, sz, comPos.Y + 0.8f);
|
||||
float minGround = underHit.SurfaceY + 0.10f * scale * env;
|
||||
float minGround = underHit.SurfaceY + 0.10f * scale * legEnv;
|
||||
ws.FootSole[i] = new Vector3(sx, MathF.Max(syBase + arcLift, minGround), sz);
|
||||
|
||||
Vector3 nBlend = Vector3.Lerp(ws.SwingStartNormal[i], ws.SwingTargetNormal[i], s);
|
||||
Vector3 nBlend = Vector3.Lerp(ws.SwingStartNormal[i], ws.SwingTargetNormal[i], legS);
|
||||
ws.FootNormal[i] = nBlend.LengthSquared() > 1e-6f ? Vector3.Normalize(nBlend) : Vector3.UnitY;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -908,7 +908,9 @@ namespace RustToDust.Tests
|
|||
var view = host.Session.World.View;
|
||||
int lane = localBody.Lane;
|
||||
|
||||
for (int t = 0; t < 6; t++)
|
||||
// Prime idle local prediction once and drain unacked inputs so client sits grounded idle with _unackedInputs.Count == 0
|
||||
client.SubmitLocalInput(new PlayerInput(0f, 0f, 0f, 40f, false, false, false), true);
|
||||
for (int t = 0; t < 10; t++)
|
||||
{
|
||||
nowMs += 16;
|
||||
host.StepOnce(nowMs);
|
||||
|
|
@ -916,6 +918,7 @@ namespace RustToDust.Tests
|
|||
client.BeginRenderFrame(1.0 / 60.0, 1f);
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
Assert.Equal(0, client.UnackedInputCount);
|
||||
|
||||
Assert.True(client.TrySampleInterpolatedWalkerPose(true, slot, 1f, out var preBlastSnap),
|
||||
"Expected local walker prediction snapshot while grounded idle");
|
||||
|
|
|
|||
|
|
@ -1895,6 +1895,8 @@ namespace RustToDust.Tests
|
|||
|
||||
var comPos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
|
||||
var qYaw = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
|
||||
var qTotal = Quaternion.Normalize(qYaw * Quaternion.CreateFromYawPitchRoll(0f, ws.LeanPitch, ws.LeanRoll));
|
||||
Vector3 pelvisWorld = Vector3.Transform(ws.PelvisOffset, qYaw);
|
||||
|
||||
for (int i = 0; i < ws.Geom.LegCount; i++)
|
||||
{
|
||||
|
|
@ -1907,8 +1909,8 @@ namespace RustToDust.Tests
|
|||
$"{spec.Id} ({map}) tick {t} leg {i}: airborne foot plunged underground ({sole.Y:F3} < {surfUnderFoot:F3})");
|
||||
}
|
||||
|
||||
Vector3 hipWorld = comPos + ws.PelvisOffset + Vector3.Transform(ws.Geom.Legs[i].HipInCom * ws.GeomScale, qYaw);
|
||||
Vector3 ankleWorld = sole + new Vector3(0f, ws.Geom.Legs[i].AnkleH * ws.GeomScale, 0f);
|
||||
Vector3 hipWorld = comPos + pelvisWorld + Vector3.Transform(ws.Geom.Legs[i].HipInCom * ws.GeomScale, qTotal);
|
||||
Vector3 ankleWorld = sole + ws.FootNormal[i] * (ws.Geom.Legs[i].AnkleH * ws.GeomScale);
|
||||
float dist3D = Vector3.Distance(ankleWorld, hipWorld);
|
||||
float maxReach = ws.Geom.Legs[i].MaxLegReach * ws.GeomScale;
|
||||
Assert.True(dist3D <= maxReach + 0.10f,
|
||||
|
|
@ -1991,10 +1993,12 @@ namespace RustToDust.Tests
|
|||
|
||||
var comPos = new Vector3(view.PositionX[lane], view.PositionY[lane], view.PositionZ[lane]);
|
||||
var qYaw = new Quaternion(player.CurrRotX, player.CurrRotY, player.CurrRotZ, player.CurrRotW);
|
||||
var qTotal = Quaternion.Normalize(qYaw * Quaternion.CreateFromYawPitchRoll(0f, ws.LeanPitch, ws.LeanRoll));
|
||||
Vector3 pelvisWorld = Vector3.Transform(ws.PelvisOffset, qYaw);
|
||||
for (int i = 0; i < ws.Geom.LegCount; i++)
|
||||
{
|
||||
Vector3 hipWorld = comPos + ws.PelvisOffset + Vector3.Transform(ws.Geom.Legs[i].HipInCom * ws.GeomScale, qYaw);
|
||||
Vector3 ankleWorld = ws.FootSole[i] + new Vector3(0f, ws.Geom.Legs[i].AnkleH * ws.GeomScale, 0f);
|
||||
Vector3 hipWorld = comPos + pelvisWorld + Vector3.Transform(ws.Geom.Legs[i].HipInCom * ws.GeomScale, qTotal);
|
||||
Vector3 ankleWorld = ws.FootSole[i] + ws.FootNormal[i] * (ws.Geom.Legs[i].AnkleH * ws.GeomScale);
|
||||
float dist3D = Vector3.Distance(ankleWorld, hipWorld);
|
||||
float maxReach = ws.Geom.Legs[i].MaxLegReach * ws.GeomScale;
|
||||
Assert.True(dist3D <= maxReach + 0.14f,
|
||||
|
|
|
|||
Loading…
Reference in a new issue