Rapier

~1.1 MB WASM

High-performance 2D and 3D physics powered by Rust and WebAssembly.


01

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.

Preview

02

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).

🦀
Rust + WebAssembly Speed
Written in Rust and compiled to WASM, Rapier runs significantly faster than pure JavaScript physics engines like Cannon.js or Matter.js.
🎯
Deterministic Simulation
The same inputs always produce the same outputs across platforms. Essential for multiplayer games, replays, and automated testing.
🔄
2D and 3D in One API
Separate @dimforge/rapier2d and @dimforge/rapier3d packages with the same API style. Pick the one you need without learning a new library.

03

When to Use Rapier

Use when
Browser games that need fast, accurate physics (platformers, puzzle games, simulations)
Multiplayer games where every player must see the same physics outcome
3D scenes with realistic object interactions (paired with Three.js or Babylon.js)
Robotics and mechanical simulations with motorized joints
Large-scale simulations with hundreds of active bodies
Avoid when
Quick prototypes without a bundler -- Rapier requires async WASM initialization; use Cannon.js or Matter.js for simpler CDN-based setups
Projects targeting older browsers without WebAssembly support
Soft body or cloth simulation -- Rapier handles rigid bodies only; use Ammo.js for soft bodies

04

How Rapier Compares

Rapier vs Cannon.js

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.

Rapier wins at
WASM performance, deterministic, active development, CCD
Cannon.js wins at
Pure JavaScript, simpler setup, CDN-friendly, more tutorials
View Full Comparison →
Rapier vs Ammo.js

Both use WASM. Rapier has a cleaner API and smaller binary. Ammo.js (Bullet port) has more features like soft bodies and vehicle physics.

Rapier wins at
Smaller binary, cleaner API, deterministic, better docs
Ammo.js wins at
Soft body physics, cloth simulation, vehicle physics, Bullet feature set
View Full Comparison →
Rapier vs Matter.js

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.

Rapier wins at
2D + 3D, WASM performance, deterministic, CCD
Matter.js wins at
Built-in renderer, simpler API, tiny bundle, no WASM needed
View Full Comparison →

05

Get Started with Rapier

Terminal
npm install @dimforge/rapier3d
# For 2D: npm install @dimforge/rapier2d
Terminal
yarn add @dimforge/rapier3d
# For 2D: yarn add @dimforge/rapier2d
HTML
<!-- 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>
Quick Start
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();

06

Related Libraries