Commit graph

3 commits

Author SHA1 Message Date
Erik
9e4772a8f8 fix(motion): project anim root motion onto terrain plane (slope staircase)
Grounded player remotes were showing a ~5 Hz Z staircase when running
up/down slopes — the rate of server UpdatePositions. Body Z stayed flat
between UPs, then ramped over ~100ms during the queue-active chase to
each new server position, then went flat again until the next UP.

Diagnosis (no diagnostic needed — the math is unambiguous):
PositionManager.ComputeOffset has two modes via
InterpolationManager.AdjustOffset:

  - Queue active (body chasing a waypoint): returns
    `(head − body) / dist × min(catchUpSpeed × dt, dist)`. 3D direction,
    Z follows server's reported Z naturally.
  - Queue empty / head-reached (within DESIRED_DISTANCE = 0.05m of the
    most recent UP): returns Vector3.Zero. ComputeOffset falls back to
    `seqVel × dt rotated into world` — pure animation root motion. Every
    locomotion cycle bakes Z=0 in body-local, so the world result has
    Z=0 too. XY advances at the running pace; Z stays at the last UP.

For a runner at maxSpeed ≈ 4 m/s with catchUpSpeed = 2× = 8 m/s and
server UPs at ~5 Hz, body covers ~0.8m per UP, chases for ~100ms
(queue-active 3D path, Z ramps), then sits in seqVel-only mode for
~100ms (Z flat) until the next UP. Visible as a 5 Hz Z staircase.

Fix mirrors retail's CTransition::adjust_offset contact-plane projection
(named-retail acclient_2013_pseudo_c.txt:272296-272346) for grounded
motion, applied at the queue-empty boundary instead of inside the sweep:

  PositionManager.ComputeOffset gains an optional Vector3? terrainNormal.
  When the seqVel-only fallback runs AND a non-trivial terrain normal is
  supplied, project rootMotionWorld onto the plane:

      result = rootMotionWorld − N × dot(rootMotionWorld, N)

  Anim XY motion gains a corresponding Z component proportional to slope
  angle × forward speed, so body Z follows the terrain mesh between UPs.
  No-op on flat ground (N ≈ +Z, dot ≈ 0); cannot regress L.3 M2's
  flat-ground verification.

GameWindow.TickAnimations grounded-remote path samples
PhysicsEngine.SampleTerrainNormal at the body's current XY each tick
and passes it to ComputeOffset. SampleTerrainNormal is a thin public
wrapper over the existing internal SampleTerrainWalkable that returns
just the plane normal (no need to expose the internal sample shape).

Diagnostic: ACDREAM_SLOPE_DIAG=1 prints a per-tick [SLOPE] line with
guid, body Z before/after, offset, queue active flag, and the sampled
plane Nz so we can grep before/after the fix and confirm Z changes
continuously between UPs on slopes.

Tests: PositionManagerTests gains two cases:
  - slope projection: 30° east-tilted plane, body running due east at
    4 m/s for 1s → expect (3.0, 0, −1.732) (descends along slope, not
    flat). Math: dot(seqVel, N) = 2.0 → result = (4,0,0) − (0.5,0,0.866)
    × 2.0 = (3.0, 0, −1.732).
  - flat-ground no-op: N = +Z, expect identical Y-only motion as the
    pre-fix behavior.

Build green. 357 pass / 6 pre-existing fail (same set as ec59a08;
verified by stashing this change). The pre-existing
`ComputeOffset_BothActive_Combined` failure reflects an outdated
additive-design test docstring; the M2 commit (40d88b9) deliberately
changed the implementation to REPLACE semantics to fix the prior
3×-server-pace overshoot.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 21:37:42 +02:00
Erik
842dfcd092 fix(motion): retail-faithful per-frame remote tick (L.3.2 follow-up)
Multi-bug fix for the env-var-gated retail-faithful remote tick path
(ACDREAM_INTERP_MANAGER=1). Combines four previously-stacked defects
into one coherent rewrite:

1. PositionManager.ComputeOffset was additive (rootMotion + correction).
   Retail's PositionManager::adjust_offset (acclient @ 0x00555190 →
   InterpolationManager::adjust_offset @ 0x00555d30) REPLACES the
   offset frame via Frame::operator=(arg2, &__return) when catch-up
   engages — it does NOT add to the rootOffset that CPartArray::Update
   wrote. Switched to "correction overrides root motion" semantics.

2. MotionInterpreter.GetMaxSpeed was returning RunAnimSpeed × rate
   (~11.7 m/s for run skill 200). The retail decomp at
   acclient_2013_pseudo_c.txt:305127 shows get_max_speed returns the
   bare run rate (~2.94) — the function's float return rides the x87
   FPU stack, which Binary Ninja shows as void. Caller multiplies by
   2.0 to get the catch-up speed. With the wrong return our catch-up
   was 23.5 m/s instead of retail's 5.88 m/s — the queue would walk
   the body 4× too aggressively.

3. The env-var TickAnimations branch was DOUBLE-COUNTING forward
   translation: it applied seqVel × dt via PositionManager.ComputeOffset
   AND let UpdatePhysicsInternal advance body.Position += body.Velocity
   × dt. Both were ~11.7 m/s for run, so body raced at 23.4 m/s —
   "way too fast" per the user. Pass seqVel=Vector3.Zero to
   ComputeOffset; let body.Velocity (refreshed per tick by
   apply_current_movement) drive the bulk translation alone.

4. Body orientation only applied sequencer.CurrentOmega per tick. For
   the running-in-circles case ACE broadcasts ForwardCommand=RunForward
   AND TurnCommand=TurnLeft on the same UpdateMotion; the sequencer
   picks the RunForward cycle whose synthesized CurrentOmega is zero,
   so body never rotated between UPs and body.Velocity stayed in an
   out-of-date world direction — the visible "rectangle when running
   circles" effect. Prefer ObservedOmega (set explicitly in
   OnLiveMotionUpdated from the wire's TurnCommand + signed TurnSpeed)
   when present; fall back to seqOmega for standalone turn cycles.

Also adds:
- Sequencer-reset call in the env-var landing-fallback so the legs
  un-fold from Falling on land (mirrors the legacy K-fix17 path).
- LastServerZ now only updates on IsGrounded UPs, so the per-tick
  landing-fallback floor doesn't drift up to the player's airborne
  peak Z and force-land mid-arc — fixes the user-reported "small
  landing in the air before landing on the ground" when jumping
  while moving.
- VEL_DIAG now samples at UP arrival with overlapping windows, plus
  TURN_WIRE / OMEGA_DIAG / FWD_WIRE diagnostics gated on
  ACDREAM_REMOTE_VEL_DIAG=1 used to trace these bugs to ground truth.

Verified via live retail-driven character observation 2026-05-03:
turn-left now rotates left (was animating right with snap), running
in circles is much smoother, jumping lands on ground (no mid-air
pause). Residual ~20% steady-state overshoot for walk remains —
WalkAnimSpeed=3.12 (decompiled retail constant) doesn't match ACE's
actual broadcast walk pace (~2.6 m/s). Tracked separately.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-03 15:24:24 +02:00
Erik
08fbbef3c4 feat(physics): PositionManager combiner class + 6 unit tests (L.3.2)
Pure-function ComputeOffset(dt, pos, seqVel, ori, interp, maxSpeed) →
Vector3. Combines animation root motion (seqVel × dt rotated by body
orientation) with InterpolationManager.AdjustOffset world-space
correction. Mirrors retail CPhysicsObj::UpdateObjectInternal
(acclient @ 0x00513730).

Composed into RemoteMotion in subsequent task (L.3.1+L.3.2 Task 3);
not yet consumed.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-03 10:13:02 +02:00