A large drag coefficient can invert velocity #32

Open
opened 2026-08-02 18:33:14 -04:00 by tachikoma · 0 comments
Collaborator

Source: TODO.md, "Arcade physics feel" (at bbb7b8f)

actor->ex -= actor->ex * self->drag_x * dt is a first-order decay, so it only
decays for drag * dt < 1. Past that it overshoots zero, and past 2 it
diverges.

With dt bounded to the default 0.05 s that needs a drag coefficient above 20,
which is not a plausible setting -- so this is a sharp edge rather than a live
defect. But nothing rejects it, and max_timestep is caller-settable, so a game
that raises the step lowers the threshold.

The exact fix is expf(-drag * dt) instead of 1 - drag * dt, which is
unconditionally stable. Three drag blocks in src/physics.c.

Files: src/physics.c (the three drag blocks)


Filed by Tachikoma (Claude Code, Opus 5, 1M context)

**Source:** TODO.md, "Arcade physics feel" (at bbb7b8f) `actor->ex -= actor->ex * self->drag_x * dt` is a first-order decay, so it only decays for `drag * dt < 1`. Past that it overshoots zero, and past `2` it diverges. With `dt` bounded to the default 0.05 s that needs a drag coefficient above 20, which is not a plausible setting -- so this is a sharp edge rather than a live defect. But nothing rejects it, and `max_timestep` is caller-settable, so a game that raises the step lowers the threshold. **The exact fix is `expf(-drag * dt)` instead of `1 - drag * dt`**, which is unconditionally stable. Three drag blocks in `src/physics.c`. **Files:** `src/physics.c` (the three drag blocks) --- Filed by Tachikoma (Claude Code, Opus 5, 1M context)
tachikoma added this to the 0.9.x milestone 2026-08-02 18:33:14 -04:00
tachikoma added the defectblast-radius:low labels 2026-08-02 18:33:14 -04:00
tachikoma added the status::grooming label 2026-08-02 18:49:18 -04:00
Sign in to join this conversation.