Matter.js Engine Configuration Options

When building 2D physics simulations with Matter.js, the Engine module serves as the central controller managing world updates, collision detection, and physical behavior. Initializing an engine via Matter.Engine.create([options]) accepts a configuration object that directly impacts simulation accuracy, physics stability, and rendering performance. Below is a complete breakdown of the properties you can define when creating a Matter.js Engine instance.


Solver Iterations

The solver iterations define how many calculation passes the physics engine executes per update step. Increasing these values yields more stable and accurate constraints and collisions, but at the cost of CPU performance.


Gravity

Gravity defines the default directional force exerted on all dynamic bodies within the engine's composite world.


Timing and Simulation Speed

The timing object configures how the engine advances the simulation clock.


Performance and Optimization


World and Collision Detection


Example Initialization

const engine = Matter.Engine.create({
  positionIterations: 8,
  velocityIterations: 6,
  constraintIterations: 4,
  enableSleeping: true,
  gravity: {
    x: 0,
    y: 1,
    scale: 0.001
  },
  timing: {
    timeScale: 1
  }
});