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; }
- Needs
@dimforge/rapier3d-compat from npm (not in the repo)
- License
MIT
- From