Matter.js MouseConstraint Configuration Options

In Matter.js, a MouseConstraint enables user interaction by allowing bodies in the physics simulation to be clicked, dragged, and thrown using a mouse or touch inputs. This article details the full range of configuration options that can be passed to the MouseConstraint.create() method, including pointer bindings, collision filters for selective grabbing, and spring constraint physics parameters.


Basic Usage

To configure a MouseConstraint, you pass an engine instance along with an optional options object to Matter.MouseConstraint.create(engine, options).

const mouse = Matter.Mouse.create(render.canvas);

const mouseConstraint = Matter.MouseConstraint.create(engine, {
  mouse: mouse,
  constraint: {
    stiffness: 0.2,
    render: {
      visible: true
    }
  },
  collisionFilter: {
    mask: 0x0001
  }
});

Core Configuration Options

1. mouse

2. constraint

3. collisionFilter

4. type


Read-Only State Properties

Once configured, the MouseConstraint exposes dynamic state properties that can be monitored inside your game or simulation loop: