Rapier
~1.1 MB WASMHigh-performance 2D and 3D physics powered by Rust and WebAssembly.
See It in Action
These demos show the physics Rapier handles -- gravity, collisions, and constraints -- running at near-native speed via Rust + WASM.
Boxes stack and a ball knocks them over -- multi-body collision with mass, gravity, and restitution that CSS cannot replicate.
What is Rapier?
Rapier is a physics engine written in Rust and compiled to WebAssembly for the browser. It simulates gravity, collisions, and constraints so objects in your scenes behave realistically -- they fall, bounce, stack, and connect with joints.
Developed by Dimforge, Rapier offers separate 2D and 3D packages (@dimforge/rapier2d and @dimforge/rapier3d). Its deterministic simulation means identical inputs always produce identical results -- important for multiplayer games and replays. The current JavaScript bindings are at version 0.19.3 (November 2025).
When to Use Rapier
How Rapier Compares
Rapier is faster (WASM) and actively maintained. Cannon.js (cannon-es fork) is easier to set up -- pure JS, no WASM init, works with a plain script tag. Pick Rapier for performance, Cannon.js for simplicity.
Both use WASM. Rapier has a cleaner API and smaller binary. Ammo.js (Bullet port) has more features like soft bodies and vehicle physics.
Different scope. Matter.js is 2D-only with a built-in renderer and tiny bundle. Rapier does 2D + 3D with better performance but needs a separate renderer and WASM setup.
Get Started with Rapier
npm install @dimforge/rapier3d
# For 2D: npm install @dimforge/rapier2d
yarn add @dimforge/rapier3d
# For 2D: yarn add @dimforge/rapier2d
<!-- Rapier requires async WASM init -- best with a bundler -->
<script type="module">
import RAPIER from "https://cdn.jsdelivr.net/npm/@dimforge/[email protected]/rapier.mjs";
await RAPIER.init();
// Ready to use
</script>
import RAPIER from "@dimforge/rapier3d-compat";
// Initialize WASM (async required)
await RAPIER.init();
// Create physics world with gravity
const gravity = { x: 0.0, y: -9.81, z: 0.0 };
const world = new RAPIER.World(gravity);
// Create a falling box
const bodyDesc = RAPIER.RigidBodyDesc.dynamic()
.setTranslation(0.0, 10.0, 0.0);
const body = world.createRigidBody(bodyDesc);
// Attach a collider (box shape)
const colliderDesc = RAPIER.ColliderDesc.cuboid(0.5, 0.5, 0.5);
world.createCollider(colliderDesc, body);
// Create a static ground
const groundBody = world.createRigidBody(
RAPIER.RigidBodyDesc.fixed()
);
world.createCollider(
RAPIER.ColliderDesc.cuboid(10.0, 0.1, 10.0),
groundBody
);
// Step the simulation
function gameLoop() {
world.step();
const pos = body.translation();
console.log("Box y:", pos.y.toFixed(2));
requestAnimationFrame(gameLoop);
}
gameLoop();