html5 javascript physics engine

Matter.js is a 2D physics engine for the web


Demo

full demo →

See the full demo for more things to try

Mobile Demo

Try the mobile demo on your mobile device.
Touch and drag to interact, tilt and turn to control gravity.

Install

Get the edge build (master) or download a stable release and include the script in your web page.
You can also install using the package managers Bower and NPM.

<script src="matter.js" type="text/javascript"></script>
bower install matter-js
npm install matter-js

Usage

See the Getting started wiki page for a minimal usage example.

Matter.js includes a sample renderer, but this is optional and it's easy to use your own.
See the Rendering wiki page for information, including on how to use your own custom game loop.

Check out the demo page for more examples and then refer to Demo.js to see how they work.
Some of the demos are also available on codepen, where you can easily experiment with them.

Documentation

Edge build documentation is at Matter.js API Docs (master)
Stable release documentation is at Matter.js API Docs (v0.8.0)

Features

  • Physical properties (mass, area, density etc.)
  • Rigid bodies of any convex polygon
  • Stable stacking and resting
  • Restitution (elastic and inelastic collisions)
  • Conservation of momentum
  • Friction and resistance
  • Constraints
  • Gravity
  • Composite bodies
  • Sleeping and static bodies
  • Events
  • Collisions (broad, mid and narrow-phase)
  • Time scaling (slow-mo, speed-up)
  • Canvas renderer (supports vectors and textures)
  • WebGL renderer (requires pixi.js)
  • World state serialisation (requires resurrect.js)
  • MatterTools for creating and testing worlds
  • Cross-browser (Chrome, Firefox, Safari, IE8+)
  • Mobile-compatible (touch, responsive)
  • Original JavaScript physics implementation

Implementation and References

The technical details are in the readme over at GitHub.
For references, see my post on Game physics for beginners.

Changelog and Status

To see what's new or changed in the latest version, see the Changelog

Matter.js is currently only alpha status, meaning the API is still in development and may change occasionally. The library is reasonably stable as-is, but it is not yet feature complete. As the project is open source, contributions are welcome!

Issues

Report issues over at GitHub.

Follow

I'll be posting updates on twitter over at @liabru

License

Matter.js is licensed under The MIT License (MIT)
Copyright (c) 2014 liabru

This license is also supplied with the release and source code.
As stated in the license, absolutely no warranty is provided.