Using Matter.js Physics in Phaser 3

Yes, you can use Matter.js with Phaser 3, and it is natively integrated directly into the framework. Phaser 3 includes an optimized version of the Matter.js 2D physics engine out of the box, allowing developers to implement advanced simulations with rigid bodies, constraints, composite shapes, and realistic mass without installing external plugins. This guide explains how Phaser 3 integrates Matter.js, how to enable it in your configuration, and when to use it over alternative physics engines.

Native Integration

Phaser 3 provides first-class support for Matter.js alongside its lightweight Arcade Physics system. You do not need to import or install Matter.js separately. Phaser wraps Matter.js's core functions into simple, game-oriented APIs exposed through scene managers and factory methods, making advanced physics accessible while retaining the full depth of Matter's native engine.

How to Enable Matter.js in Phaser 3

To use Matter.js, you specify it as the default physics engine in your game configuration object.

const config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    physics: {
        default: 'matter',
        matter: {
            gravity: { y: 1 },
            debug: true
        }
    },
    scene: [ MyScene ]
};

const game = new Phaser.Game(config);

Setting debug: true draws outlines around collision boundaries, vectors, and velocity lines, which is essential for diagnosing complex collisions during development.

Adding Matter Objects in Scenes

Once enabled, Matter.js is accessible in your scenes via this.matter. You can create standard physics bodies, sprites, or composite objects:

Key Features of Matter.js in Phaser 3

Matter.js vs. Arcade Physics

Choose Arcade Physics if you are building fast-paced 2D platformers, shoot-'em-ups, or games that require simple rectangular collision detection without realistic mass or momentum. Arcade Physics is significantly faster and uses fewer CPU resources.

Choose Matter.js if your game relies on realistic physical interactions, such as tumbling objects, stacking puzzles, rolling wheels, swinging ropes, or custom polygon-based terrain.