Lane D: the player leans into the wind (gate 2.4 — as a root pose, not a clip)

The QA pass's biggest player finding: 'stands bolt upright and unbothered'
at 65 km/h. E rendered the two Mixamo lean candidates and rejected both on
screen, and proved the deeper reason a clip can't do this: _rotOnly drops
Hips.quaternion from every clip at load, so a baked lean is discarded, and
a clip's lean axis is fixed while the wind's bearing swings. So the lean is
the ROOT, the same machine as the knockdown pitch and climbY lift.

sim (player.sim.js): sim.lean 0..1 + sim.leanDir, eased over leanSecs.
Magnitude off windBase (the ~4s EMA), NOT raw windSpeed — measured: raw
strobes the posture 8-18x/min across the storms, windBase settles it to 0-2
changes per 90s. Sustained wind = posture; the gust is already the
stumble/knock event. Suppressed on your back (pitch owns the body), braced
(TakeCover is its own hunch), and up a ladder. Bands land on the storm
rating ladder: night 1 upright, 2-3 lean, 4-5 in the gale.

view (player.js): a foot-pivot tip toward leanDir, max leanMaxRad (~17deg,
a third of a knockdown's pi/2), composed under the yaw. It's the else branch
of the pitch tip by construction — the sim guarantees lean=0 whenever
pitch>0, so they never fight.

Three asserts: magnitude scales with sustained speed, a lone gust does NOT
snap you over (windBase inertia), and it's downwind + suppressed when
floored/braced/aloft. Mutation-checked: forcing lean to 0 reddens two.
Verified live at 71 km/h — leanDir dot wind = 1.0, the figure visibly
braces. Selftest 340/0/0. This is the root lean E asked me to wire first;
whether their WindPosture additive follows is a look-at-it-together call.
This commit is contained in:
type-two 2026-07-18 01:33:47 +10:00
parent 7053623fde
commit 7758b65331
3 changed files with 96 additions and 0 deletions

View File

@ -172,6 +172,8 @@ export class PlayerView {
this._axis = new THREE.Vector3();
this._qYaw = new THREE.Quaternion();
this._qPitch = new THREE.Quaternion();
this._leanAxis = new THREE.Vector3();
this._qLean = new THREE.Quaternion();
}
/** @returns {string[]} clip names that bound to at least one bone */
@ -208,6 +210,16 @@ export class PlayerView {
if (this._axis.lengthSq() < 1e-8) this._axis.set(1, 0, 0);
this._qPitch.setFromAxisAngle(this._axis.normalize(), sim.pitch * Math.PI * 0.5);
this.root.quaternion.copy(this._qPitch).multiply(this._qYaw);
} else if (sim.lean > 1e-3) {
// Wind lean (SPRINT13): the same foot-pivot tip as the knockdown, but small and toward the
// wind's downwind bearing (leanDir) rather than the fall direction. The sim suppresses lean
// whenever pitch > 0, so these two never fight — this is the else branch by construction, not
// by luck. leanMaxRad is the whole tip; a knockdown's is π/2, so a full lean is ~a third of a
// fall. Yaw still applies underneath, so you lean while facing wherever you're walking.
this._leanAxis.set(sim.leanDir.z, 0, -sim.leanDir.x);
if (this._leanAxis.lengthSq() < 1e-8) this._leanAxis.set(1, 0, 0);
this._qLean.setFromAxisAngle(this._leanAxis.normalize(), sim.lean * sim.leanMaxRad);
this.root.quaternion.copy(this._qLean).multiply(this._qYaw);
} else {
this.root.quaternion.copy(this._qYaw);
}

View File

@ -100,6 +100,21 @@ export const TUNE = {
knockBleed: 2, // exposure drains this many × faster than it fills
pitchSecs: 0.35, // s for the body to swing down / back up (view reads sim.pitch)
// Wind lean (SPRINT13 gate 2.4). The QA pass: "the player stands bolt upright and unbothered" at
// 65 km/h. E rendered the two Mixamo lean candidates and rejected both on screen (a couch-shove
// and a bus-stop slouch), and proved the deeper reason a clip can't do this at all: _rotOnly drops
// Hips.quaternion from every clip at load (player.js:44), so a baked lean is discarded — and a
// clip's lean axis is fixed while the wind's bearing swings. So the lean is the ROOT, same machine
// as the knockdown pitch: the sim owns an angle and a direction, the view tips the body by it.
// Keyed on windBase (the ~4 s EMA), NOT raw windSpeed — measured: raw strobes the posture 8-18×/min
// across the storms, windBase settles it to 0-2 changes per 90 s. Sustained wind = posture; gust is
// already the stumble/knock event. Bands land on the storm rating ladder (D's THREADS table): night
// 1 upright all night, 2-3 lean, 4-5 in the gale.
leanWindMin: 8.3, // m/s windBase (30 km/h — the speed C's leaves start at) before you lean at all
leanWindFull: 22, // m/s windBase for a full lean — past the wildnight median, shy of its 25 peak
leanMaxRad: 0.30, // rad (~17°) of torso tip at full lean. A brace-into-it, not a fall (pitch is 0.5π)
leanSecs: 0.6, // s to reach/leave the target lean — slow, so a lull visibly lets you straighten
// A gust that can't floor you can still break your stride. Sits BELOW knockWind on purpose, so a
// storm reads as: shoved → stumbling → floored, rather than fine-fine-fine-flat-on-your-back.
// RETUNED against the real storm_02: 17 was set against a mock that injected +18 gusts, but the
@ -164,6 +179,8 @@ export class PlayerSim {
this.gust = 0; // windSpeed - windBase, clamped ≥0
this.pitch = 0; // 0 upright … 1 flat on the ground
this.knockDir = { x: 0, z: 1 }; // which way the body went down
this.lean = 0; // 0 upright … 1 full wind-lean (view reads this + leanDir)
this.leanDir = { x: 0, z: 1 }; // unit downwind — the way the wind is trying to push you
this.climbY = 0; // m above the ground; >0 means you're up a ladder
this.climbTarget = 0; // where ladder.js asked you to be
@ -180,6 +197,9 @@ export class PlayerSim {
get clip() { return STATES[this.state].clip; }
get speed() { return Math.hypot(this.vel.x, this.vel.z); }
/** Radians of torso tip at a full wind-lean. Surfaced so PlayerView reads it, not TUNE. */
get leanMaxRad() { return this.tune.leanMaxRad; }
/** How high this person's hands get right now. The gate on reaching a fascia bracket. */
get reachY() { return this.pos.y + this.climbY + this.tune.reach; }
@ -381,6 +401,22 @@ export class PlayerSim {
const pstep = dt / T.pitchSecs;
this.pitch = clamp(this.pitch + clamp(wantPitch - this.pitch, -pstep, pstep), 0, 1);
// --- wind lean: the sim owns it exactly like pitch, so the view stays a pure reader and the lean
// is deterministic (dt,t). Off windBase, not ws, so a gust punches the stumble/knock event
// while the posture holds. Suppressed where a lean would fight another root pose: on your back
// (pitch owns the body), braced (TakeCover is its own hunch), or up the ladder (you're pinned
// to the rungs, not standing in the wind). It eases to 0 there rather than snapping. ---
const leanOK = this.pitch < 1e-3 && this.state !== 'shelter' && !up;
const leanSpan = Math.max(1e-3, T.leanWindFull - T.leanWindMin);
const wantLean = leanOK
? clamp((this.windBase - T.leanWindMin) / leanSpan, 0, 1)
: 0;
const lstep = dt / T.leanSecs;
this.lean = clamp(this.lean + clamp(wantLean - this.lean, -lstep, lstep), 0, 1);
// downwind is where the wind blows TOWARD; track it only while there's a wind to read, so a lull
// leaves the last bearing rather than snapping leanDir to a default and twisting the body.
if (ws > 0.1) { const inv = 1 / ws; this.leanDir.x = wx * inv; this.leanDir.z = wz * inv; }
// --- locomotion state from actual speed (so shove/slow can't desync the feet).
// `aloft` is what holds you in atTop: it's unlocked (so hold-E works up there), and without
// this guard the speed check would immediately re-state you to idle and drop you off. ---

View File

@ -175,6 +175,54 @@ export default async function run(t) {
`shove must grow faster than linearly with speed: ${p15.toFixed(3)} -> ${p30.toFixed(3)}`);
});
// ---------------------------------------------------------------- wind lean (SPRINT13 gate 2.4)
t.test('lean: calm leaves you upright, wind tips you, and it scales with the sustained speed', () => {
const calm = new PlayerSim();
drive(calm, 20, {}, windX(TUNE.leanWindMin - 3)); // below the threshold, all storm
assertLess(calm.lean, 1e-3, 'under leanWindMin you stand up straight');
const mid = new PlayerSim();
drive(mid, 40, {}, windX((TUNE.leanWindMin + TUNE.leanWindFull) / 2));
assert(mid.lean > 0.35 && mid.lean < 0.65, `mid wind is a partial lean, got ${mid.lean.toFixed(2)}`);
const gale = new PlayerSim();
drive(gale, 40, {}, windX(TUNE.leanWindFull + 6));
assertClose(gale.lean, 1, 1e-2, 'past leanWindFull you are fully into it');
assert(gale.lean >= mid.lean, 'more sustained wind is more lean');
});
t.test('lean: keys on the SUSTAINED base, not the gust — a single gust does not snap you over', () => {
const s = new PlayerSim();
drive(s, 30, {}, windX(4)); // learn a calm baseline: no lean
const before = s.lean;
drive(s, 1.2, {}, windX(TUNE.leanWindFull + 10), 30); // one big gust, shorter than leanSecs momentum
// windBase barely moves in 1.2 s (baseTrack ~4 s memory), so the posture must not jump to full.
assertLess(s.lean, 0.5, `a brief gust is a stumble, not a lean — got ${s.lean.toFixed(2)} from ${before.toFixed(2)}`);
});
t.test('lean: it points downwind, and it is suppressed on your back, braced, or up a ladder', () => {
// downwind: wind blowing +X should tip leanDir toward +X.
const s = new PlayerSim();
drive(s, 30, {}, windX(TUNE.leanWindFull + 5));
assert(s.lean > 0.5, 'leaning');
assertClose(s.leanDir.x, 1, 1e-6, 'leanDir points the way the wind blows (x)');
assertClose(s.leanDir.z, 0, 1e-6, 'and not sideways (z)');
// braced: holding C must zero the lean — TakeCover is its own pose.
const braced = new PlayerSim();
drive(braced, 30, { shelter: true }, windX(TUNE.leanWindFull + 5));
assertEq(braced.state, 'shelter', 'C braces');
assertLess(braced.lean, 1e-2, 'and a brace is not a lean');
// knocked down: pitch owns the body, lean eases out.
const floored = new PlayerSim();
drive(floored, 30, {}, windX(TUNE.leanWindFull + 5));
assert(floored.lean > 0.5, 'leaning before the fall');
floored.knockdown(0, 1, 0);
drive(floored, 1, {}, windX(TUNE.leanWindFull + 5));
assertLess(floored.lean, 1e-2, 'flat on your back is not a lean');
});
// ---------------------------------------------------------------- knockdown
t.test('knockdown: needs SUSTAINED overload, like a sail corner letting go', () => {
const brief = new PlayerSim();