Matter.js
2D rigid body physics engine for web and game development.
2. Maintained
github.com/liabru/matter-js3. Used by agents' projects
Dependency in 5 public GitHub projects set up for AI coding agents that we scanned (0.1%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What Matter.js does
Matter.js is an original JavaScript 2D rigid body engine, not a port, that ships its own canvas renderer and a long list of live demos whose source sits in the repo.
Matter.js popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How Matter.js is used
- Matter.js is a dependency in 5 of the 6,258 public GitHub projects set up for AI coding agents that we scanned, too few to describe it from them alone. Our scan also samples projects by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750); counting those, it appears in 34 projects, and what it is used with below comes from all of them.
- The most used alternative in our scan is Phaser (12 projects).
- Projects that use it most often also use Three.js (73.5%), React Three Fiber (70.6%), React (94.1%).
Often used with
Matter.js in practice
Strengths
The README lists the engine as "An original JavaScript physics implementation (not a port)". The API is written for JavaScript from the start, not translated from another engine.
The feature list claims support for Chrome, Firefox, Safari and IE8+, plus Node.js. It also lists touch input and responsive layouts for mobile.
The feature list covers compound and composite bodies and concave and convex hulls. There is a demo that builds bodies from concave SVG paths.
Collision queries (raycasting and region tests), camera-like views with translate and zoom, and time scaling are all part of the core feature list.
Watch out for
The README warns that bundlers and frameworks may reduce real-time performance with their default configs, especially in development modes.
The README names two specific culprits: Webpack's default sourcemap config and Vue.js watchers. It points to GitHub issue #1001 for fixes, not to a setting in the library itself.
World state serialisation is listed as a feature, but it requires the separate resurrect.js project.
Install from npm
npm install matter-jsMore about Matter.js
Packages around it
- three: 3D rendering
- @react-three: Three.js in React
- react: UI library
- framer-motion: React animation
- react-router-dom: Client routing
- gsap: Tween animation
Alternatives
Matter.js This page
Fast, free HTML5 game framework for building 2D games for desktop and mobile.
Get started
Install it.
npm install matter-jsRules for your agent
## Matter.js
- Install with `npm install matter-js`. If you load it with a script tag, use a stable release from the tags, not the experimental alpha build on master.
- Start from the Getting started wiki page. Its minimal example is meant to run in both browsers and Node.js.
- When the project has its own game or render loop, follow the Running and Rendering wiki pages instead of assuming the built-in canvas renderer.
- If the simulation stutters in development, check the bundler before the physics. Webpack's default sourcemap config and Vue.js watchers are known causes (see issue #1001).
- World state serialisation needs resurrect.js. Add it explicitly before saving or restoring worlds.
- Before writing a feature from scratch, look for the matching demo in the repo's `examples` directory, then for a plugin in the wiki's List of plugins.