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.

Status

Matter.js is currently only alpha status, so production use should be avoided.

This engine is the result of learning game physics and getting a bit carried away.
There's no intention to compete with other engines, so I'm not sure yet if it will be developed further.
That said, the engine is reasonably stable and performs well, it's just not feature complete.

Though if I get time and people are interested, I may continue working on it.
As the project is open source, contributions are welcome!

Install

Download matter-0.8.0.js or matter-0.8.0.min.js and include the script in your HTML file:

<script src="matter-0.8.0.js" type="text/javascript"></script>

For the latest features try the edge version (master), but it may not be fully stable.

Usage

See Demo.js and DemoMobile.js for many usage examples.
When loaded, all modules and functions are under the global Matter.* namespace.

Some of the demos are now avaliable at codepen.io/liabru, where you can easily experiment with them!

Documentation

See the Matter.js API Docs (v0.8.0)

If you're using the edge version (master) see the API Docs (master).

Changelog

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

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

The technical details for physics nerds and game devs are over at GitHub.

References

See my post on Game physics for beginners.

Issues

Report issues over at GitHub.

Twitter

If you're interested in seeing where this thing goes
I'll be posting any updates on twitter over at @liabru

Similar Projects

If you need a more complete engine, check out jswiki's list of Physics libraries.

License

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

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