Rapier setup with a fixed timestep

three.js and WebGL · 3D · MIT

What it does

How to add real physics to a three.js scene: Rapier's world, a 1/60 s fixed step fed by a clamped accumulator, bodies and colliders, syncing meshes from bodies in one place, CCD for fast bodies, and sensors that need active events. Also a ladder for when to use custom collision, Rapier, cannon-es, Jolt or Ammo. A fixed step is what makes a simulation repeatable.

Get it

npm install @dimforge/rapier3d-compat; await RAPIER.init(); const world = new RAPIER.World({ x: 0, y: -9.81, z: 0 }); accumulator += Math.min(dt, 0.1); while (accumulator >= 1/60) { world.step(); accumulator -= 1/60; }

Source on GitHub
Needs

@dimforge/rapier3d-compat from npm (not in the repo)

License

MIT

License notes are on the pack's page

From

Three.js Game Skills

Everything from Three.js Game Skills in the gallery

Back to the Asset Library