fix(physics): jump apex velocity zeroing bug

SmallVelocity threshold (0.25 m/s) in UpdatePhysicsInternal was zeroing
velocity every frame while airborne at the jump apex. With vel~0.01 m/s
and gravity adding only 0.012/frame, the zeroing won every frame and
the character got stuck at peak height forever.

Fix: only apply small-velocity zeroing when OnWalkable (grounded).
While airborne, gravity must accumulate freely through the zero-crossing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-04-14 10:13:27 +02:00
parent 157ed9d974
commit 31cd5480dc
3 changed files with 32 additions and 8 deletions

View file

@ -298,7 +298,10 @@ public sealed class PhysicsBody
calc_friction(dt, velocityMag2);
// If velocity fell below the "small" threshold after friction, stop.
if (velocityMag2 - SmallVelocitySquared < 0.0002f)
// Only apply when grounded — while airborne, gravity must accumulate
// even when velocity is near zero (e.g., at jump apex).
if (velocityMag2 - SmallVelocitySquared < 0.0002f
&& TransientState.HasFlag(TransientStateFlags.OnWalkable))
Velocity = Vector3.Zero;
// Euler integration: position += v*dt + 0.5*a*dt²