Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 16.5 — A Test Ride
3D Web · Example 1 of 2

A scripted test ride

The real physics.js of the build, inlined, with a stand-in bike. Fixed step counts, so the numbers are the same every run.

A small game is a loop of input, physics and camera: held keys or buttons set forces, the world steps at a fixed rate, the camera follows, and a watchdog resets the bike when it falls over. Script the input with fixed steps and the whole ride becomes testable.

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 boost key (B) that doubles the pedal force while held.

02

Make the watchdog reset a fallen bike after half a second instead of one.

Explain it without notes

01

Walk through one frame of the test ride: from a held key to a moved camera.

02

Why does the ride use forces and damping instead of setting the bike's velocity directly?

A scripted test ride
Press Run to see the page.
idle

Console

Nothing logged yet.

Expected console output

settled on the track     x -0.00 | speed 0.00 m/s | y -0.00 | tilt -0.0°
2 s pedalling            x 2.46 | speed 2.23 m/s | y -0.00 | tilt -0.0°
1 s braking              x 3.04 | speed 0.05 m/s | y -0.00 | tilt -0.0°
8 s more pedalling       x 25.28 | speed 4.31 m/s | y -0.00 | tilt -0.0°
highest point over the ramp: 0.12 m | the camera followed: 25.28 m