SENN Content NetworkIdeas worth building on.Explore the network
Simulation

Physics in the browser: define the simulation first

Choose body control deliberately and build fixed-step replay fixtures with Rapier's documented determinism conditions.

Revised and condensed from related Studio7 drafts. Proposed workflows are distinguished from validated implementations.

An illustrative robotics workspace with a mechanical arm and a small building model.
AI-generated editorial image · Signal Tower

A physics engine can make an object fall convincingly. That is not the same as validating a structure, reproducing a machine, or synchronizing a multiplayer world.

Start by defining which kind of simulation the application needs and what evidence will establish that it works.

Choose representations deliberately

A visual mesh and a collision shape have different jobs. A detailed render mesh may be unnecessarily expensive or unsuitable for stable collision behavior.

Use collision shapes that preserve the interactions that matter. Record their scale, orientation, and relationship to the visible object.

A scene in meters cannot safely consume model coordinates that were interpreted as inches without conversion. Unit errors can look like solver instability.

Own the time step

A display frame can arrive late or early. The simulation needs a deliberate stepping policy rather than blindly accepting every display interval as physical time.

Decide how to handle accumulated time, how many catch-up steps are allowed, and what happens after a long background pause. Interpolating the rendered pose can smooth presentation without changing the simulation’s authoritative state.

Test the application at different display rates and under artificial delay.

Understand body behavior

Static, dynamic, and kinematic bodies represent different kinds of control. A kinematic object moved directly by the application should not be treated as though forces alone determined its motion.

The Rapier rigid-body guide explains these choices and their interactions. Select the body type to match the intended behavior.

Tuning friction or mass to conceal a wrong body type usually creates another problem later.

Test determinism within its conditions

Reproducibility depends on identical initial state, operation order, inputs, and the engine’s documented constraints.

Rapier’s determinism guidance describes the conditions relevant to its JavaScript version. Do not extend a library’s guarantee to an application that uses inconsistent inputs or uncontrolled external math.

Record snapshots and input sequences. Compare states at known steps, not only the final screenshot.

Keep the boundary efficient

A worker can move simulation work away from the UI thread, but messages and copies still cost time. Define a compact exchange format and a stable identity for each simulated object.

Avoid sending a complete complex scene every frame when only a subset of transforms changed.

Also decide which side owns removal. A deleted visual object should not remain as an invisible collider.

Make deterministic replay an explicit fixture

Rapier’s current JavaScript determinism guidance describes cross-platform determinism for the same version, initial conditions, and sequence of world changes. It also warns that initialization through operations such as Math.sin or Math.cos can introduce cross-platform differences.

Record the library build, serialized initial world, fixed timestep, input sequence, and creation/deletion order. Replay the same number of simulation steps before comparing snapshots. Rendering timestamps and display frame counts should not determine the simulated duration.

A snapshot match supports reproducibility under those conditions. It does not show that a contact model matches the real object or that a browser will meet a performance target.

Choose body control before tuning contact

Rapier’s rigid-body guide distinguishes dynamic, fixed, and kinematic bodies, including position-based and velocity-based kinematic control. Choose the body type according to who owns motion.

For an animated platform that should influence other bodies while following an authored path, test the appropriate kinematic control rather than repeatedly teleporting a dynamic object and expecting ordinary physical behavior. For a freely falling part, use a dynamic body with a collider and suitable mass properties.

Create three small scenes before a large simulation: a resting stack, a moving platform carrying an object, and a fast object approaching a thin obstacle. Vary the fixed step and relevant collision settings one at a time. Record penetration, drift, missed contact, and simulation cost.

Keep these fixtures with the application when upgrading Rapier. A deterministic change in behavior can still be a regression for the product, so compare against the intended physical and interaction requirements as well as the previous snapshot.

Know what the result proves

A stable stack of boxes demonstrates one test scene. It does not establish code compliance, engineering capacity, or a device-wide performance guarantee.

Use known cases, repeatable inputs, and failure scenarios appropriate to the application. Report the browser, engine version, scene, and measured behavior.

The useful achievement is a simulation whose assumptions you can explain and whose behavior you can reproduce.

03

Keep a good idea close.
Follow Signal Tower

Keep reading

A few more good questions.

A place in your reading list

Good ideas, at your pace.

Follow Signal Tower in your favorite feed reader. No inbox required.

Follow the journal