Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 16.2 — The Fixed Timestep
3D Web · Example 2 of 2

A fast bolt and a thin shelf, in Rapier

Rapier 0.21.0 with its default settings. Against a fixed shelf, its speculative contacts stop the bolt at every speed tried.

Physics must step by the same amount of time every time, whatever the frame rate. An accumulator collects real time and runs as many fixed steps as fit. Steps are jumps, so fast objects can skip past thin ones; engines add tricks against that, and you still test it.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 4 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write createFixedStepper(step, onStep) returning { tick(delta) } with the accumulator and the cap.

02

Extend it to return alpha from tick for interpolation.

Explain it without notes

01

Why does physics use a fixed timestep, and how does the accumulator make it work at any frame rate?

02

What is tunnelling, and what can you do about it?

A fast bolt and a thin shelf, in Rapier

Console

(nothing was printed)

Expected console output

  40 m/s, CCD off: after 1 s y =   0.02 -> stopped on the shelf
  40 m/s, CCD on : after 1 s y =   0.02 -> stopped on the shelf
 200 m/s, CCD off: after 1 s y =   0.02 -> stopped on the shelf
 200 m/s, CCD on : after 1 s y =   0.02 -> stopped on the shelf
1000 m/s, CCD off: after 1 s y =   0.02 -> stopped on the shelf
1000 m/s, CCD on : after 1 s y =   0.02 -> stopped on the shelf