Best Physics Engine for Web Games

Updated June 2026
Rapier is the best overall physics engine for web games in 2026, offering the highest performance through WASM with SIMD, strong 2D and 3D support, and an active community. Havok is the best choice if you are using Babylon.js. Cannon-es is ideal when you want pure JavaScript simplicity and do not need WASM. For 2D-only games, Matter.js and Planck.js are lightweight and capable alternatives.

The Full Comparison

Choosing a physics engine for a browser game means balancing performance, ease of use, bundle size, community support, and compatibility with your renderer. There is no single best engine for every project, but there is a clear best engine for most common scenarios. Here is how each option stacks up across the factors that matter.

Rapier: Best for Performance and Flexibility

Rapier is written in Rust and compiled to WebAssembly. Its SIMD-accelerated npm packages (rapier2d-simd, rapier3d-simd) are between two and five times faster than its own 2024 releases, making it the fastest physics engine available in a browser as of mid-2026. It supports both 2D and 3D simulation through separate packages with nearly identical APIs.

Rapier provides rigid bodies, colliders (box, sphere, capsule, cylinder, cone, convex hull, trimesh, heightfield), joints (revolute, prismatic, fixed, ball, spring), a built-in character controller, ray casting, shape casting, and intersection queries. Its dynamic BVH broadphase handles thousands of bodies efficiently. The documentation is thorough, and the React Three Fiber community has built react-three-rapier for declarative Three.js integration.

The main downside is the async WASM initialization step, which adds a small amount of loading complexity. The WASM binary adds about 500 KB to the bundle (compressed). Debugging WASM code is harder than debugging JavaScript, though Rapier's API surface is clean enough that most issues come from configuration, not engine bugs.

Choose Rapier when: you need the best performance, you are building a 3D game with Three.js or a custom renderer, you have more than a few hundred bodies, or you need both 2D and 3D physics in the same project.

Cannon-es: Best for JavaScript Simplicity

Cannon-es is a pure JavaScript 3D physics engine with zero native dependencies. It installs, imports, and runs immediately with no async initialization or WASM loading. Its API is clean and mirrors Three.js conventions, making it the most natural pairing for Three.js projects that prioritize simplicity.

Cannon-es supports rigid bodies, multiple shape types (box, sphere, plane, cylinder, convex polyhedron, trimesh, heightfield), constraints (point-to-point, hinge, lock, distance, spring), materials with friction and restitution, sleep management, and a raycast vehicle class. The pmndrs community maintains it alongside use-cannon for React integration.

Performance is the main limitation. Cannon-es handles up to about 500 active bodies at 60 fps on a typical desktop. Beyond that, the pure JavaScript solver cannot keep up with WASM engines. The engine is also 3D-only; there is no 2D mode, though you can constrain all motion to a plane manually.

Choose Cannon-es when: you want the simplest possible integration, your game has under 500 dynamic bodies, you prefer debuggable JavaScript over WASM, or you are building a Three.js game and want matching API conventions.

Havok: Best for Babylon.js Projects

Havok is an industry-standard physics engine from Microsoft, available as a free WASM module under the MIT license since Babylon.js 6. It is the default physics backend for Babylon.js and integrates deeply: physics bodies are attached to meshes, transforms sync automatically, and the step loop runs inside the scene's render cycle with no manual wiring.

Performance is excellent, up to 20 times faster than the older Ammo.js backend and comparable to Rapier for most benchmarks. Havok supports rigid bodies, collision shapes (including mesh shapes for static geometry), constraints (ball-and-socket, hinge, slider, lock, spring), character controllers, and collision filtering with bitmasks.

The downside is tight coupling to Babylon.js. While the WASM module can technically be used standalone, there is no documented standalone API. If you are using Three.js, Phaser, or a custom renderer, Havok is not a practical option. It also requires WebAssembly SIMD, excluding iOS devices below version 16.4.

Choose Havok when: you are building your game in Babylon.js and want the best integrated physics experience with the least setup code.

Ammo.js: Legacy Option with Broad Features

Ammo.js is an Emscripten port of the Bullet physics engine. It was the standard web physics engine before Rapier and Havok arrived. Ammo.js supports a wide feature set inherited from Bullet: rigid bodies, soft bodies, compound shapes, vehicle dynamics, ghost objects, and constraint motors. It runs as either JavaScript or WASM.

The API is the main drawback. It mirrors Bullet's C++ interface directly, with manual memory management (you must call Ammo.destroy() on every object you create), verbose constructor calls, and no TypeScript types. Debugging is difficult because the Emscripten wrapper obscures the call stack. Performance is adequate but not competitive with Rapier or Havok for large simulations.

Choose Ammo.js when: you need a specific Bullet feature that other engines lack (soft bodies, advanced vehicle dynamics), or you are maintaining a legacy project that already uses it.

Matter.js: Best for 2D Prototyping

Matter.js is a 2D physics engine with a friendly API and a built-in renderer for quick prototyping. It handles rigid bodies, composites (groups of bodies and constraints), collision detection with SAT, sleeping, and basic constraints. The built-in renderer lets you see physics behavior immediately without setting up a separate rendering system.

Matter.js is well suited for casual 2D games, physics puzzles, and educational projects where ease of use matters more than raw performance. It handles a few hundred bodies at 60 fps. The API is intuitive and well documented, with many community examples and tutorials available.

Choose Matter.js when: you are building a 2D game and want the fastest path from idea to working prototype, or when you are learning physics simulation concepts.

Planck.js: Best for Precise 2D Simulation

Planck.js is a JavaScript port of Box2D, the engine behind Angry Birds and hundreds of other 2D games. It offers more precise simulation than Matter.js, with a proper iterative solver, continuous collision detection, and a wider range of joint types. The API is more technical than Matter.js but produces more accurate and stable results.

Choose Planck.js when: you are building a 2D game that requires precise physical behavior (stacking, fine-grained collision response, complex joints) and you need better simulation quality than Matter.js provides.

Which engine has the best Three.js integration?
Rapier, through the react-three-rapier library for React Three Fiber projects, or through manual synchronization for vanilla Three.js. Cannon-es is also a strong choice for Three.js thanks to its matching API conventions and the use-cannon React wrapper.
Can I switch engines later?
Yes, if your code separates physics from rendering cleanly. The physics world and the render scene are independent systems. Swapping the engine means replacing the world setup, body creation, and sync loop, but your rendering code, game logic, and asset pipeline stay the same. The core concepts (bodies, shapes, forces, constraints) map directly between engines.
Do I need a physics engine for a simple platformer?
Usually no. Simple platformers with tile-based collision and predictable movement work better with hand-written physics code that gives you exact control over jump feel, acceleration curves, and collision response. See the engine vs hand-rolled comparison for a detailed breakdown.
How much does WASM vs JavaScript matter for performance?
For small simulations (under 100 bodies), the difference is negligible. For medium simulations (100 to 500 bodies), WASM engines like Rapier are roughly twice as fast. For large simulations (500 or more bodies), WASM can be five times faster or more, which makes the difference between hitting 60 fps and dropping to 30.

Summary Table

Engine Language Dimensions Best Pairing Body Limit (60 fps)
Rapier Rust/WASM 2D and 3D Three.js, any renderer 2,000+
Cannon-es JavaScript 3D Three.js ~500
Havok C++/WASM 3D Babylon.js 2,000+
Ammo.js C++/WASM 3D Babylon.js, Three.js ~1,000
Matter.js JavaScript 2D Canvas, PixiJS ~300
Planck.js JavaScript 2D Canvas, PixiJS, Phaser ~500
Key Takeaway

For most 3D web games, start with Rapier for performance or Cannon-es for simplicity. If you use Babylon.js, choose Havok. For 2D games, Matter.js gets you started fast and Planck.js offers better simulation quality. Match the engine to your renderer, your body count, and your tolerance for WASM complexity.