Matter.js simulates 2D rigid-body physics for browser games and interactive pages. It runs in modern browsers and Node.js with canvas rendering and touch-friendly controls.
Overview
Matter.js is a JavaScript implementation of two-dimensional rigid body dynamics aimed at web projects. Developers add bodies, constraints, and forces to build stacks, vehicles, cloth-like setups, and arcade-style interactions with collision detection across broad, mid, and narrow phases.
The engine supports compound and composite bodies, concave and convex hulls, friction, restitution, sleeping static bodies, gravity, raycasting, and collision filtering. A built-in canvas renderer can draw vectors and textures, while plugins add rounded corners, camera views, time scaling, and extra query helpers.
Demos on the project site illustrate stacks, bridges, soft bodies, slingshot games, and similar scenes. The package installs through npm or Yarn and can be bundled into larger front-end toolchains, though some bundler defaults may affect real-time performance in development.
Matter.js is written as an original JavaScript physics core rather than a port from another language, and targets cross-browser desktop use plus mobile touch input.
Key features
- Rigid and compound bodies
- Concave and convex collision shapes
- Constraints and gravity
- Friction and restitution
- Canvas renderer with textures
- Raycasting and region queries
- Sleeping and static bodies
- Plugin extension system
Use cases
- Browser-based physics games
- Interactive diagrams and demos
- Stacking and collision puzzles
- Soft-body and cloth experiments