Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 16.1 — Physics Engines
3D Web · Example 1 of 2

Start Rapier, then drop a ball

Rapier 0.21.0. The numbers are the same on every machine: the engine is deterministic for the same inputs and steps.

A physics engine keeps its own world of bodies (things with mass and motion) and colliders (their shapes), applies gravity and contacts, and moves everything forward one step at a time. Rapier runs as WebAssembly: you must await RAPIER.init() before using 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

Add a second ball with restitution 0 next to the first, and print both heights.

02

Make the floor a fixed body explicitly, instead of a collider without a body.

Explain it without notes

01

What is the difference between a rigid body and a collider?

02

Why must you await RAPIER.init(), and what happens if you don't?

Start Rapier, then drop a ball

Console

(nothing was printed)

Expected console output

world before init: TypeError: Cannot read properties of undefined (reading 'rawintegrationparameters_new')
rapier version: 0.21.0
timestep: 0.01666666753590107
step 20: y = 1.448
step 40: y = 0.399
step 60: y = 0.350
step 80: y = 0.350
step 100: y = 0.350
step 120: y = 0.350