Skip to content
Frontend
Skill

/physics-matter

Use this skill when using Matter.js physics in Phaser 4. Covers rigid bodies, constraints, composite bodies, sensors, collision filtering, world configuration, and advanced physics shapes. Triggers on: Matter, matter physics, constraint, joint, rigid body, sensor.

From plugin
phaser
41k28 skills

Claude Code

$ npx -y skills add phaserjs/phaser --skill physics-matter --agent claude-code

SKILL.md

physics-matter.SKILL.md
name: physics-matter
description: "Use this skill when using Matter.js physics in Phaser 4. Covers rigid bodies, constraints, composite bodies, sensors, collision filtering, world configuration, and advanced physics shapes. Triggers on: Matter, matter physics, constraint, joint, rigid body, sensor."

Matter.js Physics

> Setting up and using Matter.js physics in Phaser 4 -- full-body physics with rigid bodies, compound bodies, constraints, composites, sensors, collision filtering, pointer dragging, tilemap integration, and debug rendering.

**Key source paths:** `src/physics/matter-js/MatterPhysics.js`, `src/physics/matter-js/World.js`, `src/physics/matter-js/Factory.js`, `src/physics/matter-js/MatterSprite.js`, `src/physics/matter-js/MatterImage.js`, `src/physics/matter-js/MatterGameObject.js`, `src/physics/matter-js/PointerConstraint.js`, `src/physics/matter-js/MatterTileBody.js`, `src/physics/matter-js/components/`, `src/physics/matter-js/events/`, `src/physics/matter-js/typedefs/` **Related skills:** ../game-setup-and-config/SKILL.md, ../sprites-and-images/SKILL.md, ../physics-arcade/SKILL.md, ../tilemaps/SKILL.md

Quick Start

class GameScene extends Phaser.Scene {
    create() {
        // Matter sprite (dynamic, has animation support)
        this.player = this.matter.add.sprite(400, 200, 'player');
        this.player.setBounce(0.5);
        this.player.setFriction(0.05);

        // Matter image (dynamic, no animation)
        const box = this.matter.add.image(300, 100, 'crate');

        // Static body from raw shape
        this.matter.add.rectangle(400, 580, 800, 40, { isStatic: true });

        // Enable pointer dragging on all bodies
        this.matter.add.mouseSpring();

        this.cursors = this.input.keyboard.createCursorKeys();
    }

    update() {
        if (this.cursors.left.isDown) {
            this.player.setVelocityX(-5);
        } else if (this.cursors.right.isDown) {
            this.player.setVelocityX(5);
        }
        if (this.cursors.up.isDown && this.player.body.velocity.y > -0.1) {
            this.player.setVelocityY(-10);
        }
    }
}

// Enable Matter physics in game config
const config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    physics: {
        default: 'matter',
        matter: {
            gravity: { y: 1 },
            enableSleeping: true,
            debug: true,
            setBounds: true    // walls around canvas edges
        }
    },
    scene: GameScene
};

const game = new Phaser.Game(config);

Core Concepts

Scene Plugin (`this.matter`)

The `MatterPhysics` class is the scene-level plugin. Key properties:

  • **`this.matter.add`** -- `Factory` for creating bodies, constraints, Game Objects (auto-added to world).
  • **`this.matter.world`** -- `World` instance managing the engine, bounds, debug rendering. Extends `EventEmitter`.
  • **`this.matter.body`** / **`bodies`** / **`composite`** / **`composites`** / **`constraint`** -- Direct references to Matter.js modules for low-level use.
  • **`this.matter.bodyBounds`** -- Helper for aligning bodies by visual bounds.

World (`this.matter.world`)

  • **`engine`** -- The `MatterJS.Engine` instance.
  • **`localWorld`** -- The `MatterJS.World` composite containing all bodies and constraints.
  • **`enabled`** -- Boolean; `false` pauses simulation. **`autoUpdate`** -- `true` = engine updates each game step.
  • **`walls`** -- `{ left, right, top, bottom }` boundary wall bodies (or null).

World Config (`MatterWorldConfig`)

Passed under `physics.matter` in game or scene config:

| Property | Default | Purpose | |---|---|---| | `gravity` | `{ x: 0, y: 1 }` | Gravity vector. Set `false` to disable | | `setBounds` | `false` | `true` or `{ x, y, width, height, thickness, left, right, top, bottom }` | | `enableSleeping` | `false` | Allow bodies to sleep when at rest | | `positionIterations` | `6` | Position solving accuracy | | `velocityIterations` | `4` | Velocity solving accuracy | | `constraintIterations` | `2` | Constraint stability | | `timing.timeScale` | `1` | `0` freezes, `0.5` slow-motion | | `autoUpdate` | `true` | Auto-step each game frame | | `debug` | `false` | `true` or `MatterDebugConfig` object | | `runner` | `{}` | Use `runner.fps` for fixed timestep |

Matter Game Objects

Phaser provides two physics-aware Game Object classes and a function to add physics to any Game Object:

  • **`Phaser.Physics.Matter.Sprite`** -- Extends `Sprite` with all Matter components. Created via `this.matter.add.sprite(x, y, key, frame, options)`. Supports animations.
  • **`Phaser.Physics.Matter.Image`** -- Extends `Image` with all Matter components. Created via `this.matter.add.image(x, y, key, frame, options)`. No animation support, lighter weight.
  • **`MatterGameObject(world, gameObject, options)`** -- Injects all Matter components into any existing Game Object. Created via `this.matter.add.gameObject(mySprite, options)`.

Both `MatterSprite` and `MatterImage` default to a rectangle body matching the texture size. Pass `options.shape` to override.

Matter Components (Mixins)

All Matter Game Objects have these component methods mixed in:

| Component | Key Methods | |---|---| | **Velocity** | `setVelocity(x, y)`, `setVelocityX(x)`, `setVelocityY(y)`, `getVelocity()`, `setAngularVelocity(v)`, `getAngularVelocity()`, `setAngularSpeed(s)`, `getAngularSpeed()` | | **Force** | `applyForce(vec2)`, `applyForceFrom(position, force)`, `thrust(speed)`, `thrustLeft(speed)`, `thrustRight(speed)`, `thrustBack(speed)` | | **Bounce** | `setBounce(value)` -- restitution, 0 to 1 | | **Friction** | `setFriction(value, air?, fstatic?)`, `setFrictionAir(value)`, `setFrictionStatic(value)` | | **Mass** | `setMass(value)`, `setDensity(value)`, `centerOfMass` (getter) | | **Gravity** | `setIgnoreGravity(bool)` | | **Sensor** | `setSensor(bool)`, `isSensor()` | | **Static** | `setStatic(bool)`, `isStatic()` | | **Sleep** | `setToSleep()`, `setAwake()`, `setSlee

Read more
@phaserjs
Ships withphaser

Phaser is a fast, free, and fun open source HTML5 game framework that offers WebGL and Canvas rendering across desktop and mobile web browsers and has been actively developed for over 13 years.

Stars on GitHub

Momentum

stars in total
40.7k
Star history of phaserjs/phaser on GitHub, a chart by star-history.com

Other skills on phaser.

actions-and-utilities

actions-and-utilities

Use this skill when working with Phaser 4 utility functions, actions, alignment, grid layout, or batch operations on game…

@phaserjs@phaserjsInstall Skill
animations

animations

Use this skill when creating or controlling sprite animations in Phaser 4. Covers spritesheets, atlases, AnimationManager,…

@phaserjs@phaserjsInstall Skill
audio-and-sound

audio-and-sound

Use this skill when adding audio or sound to a Phaser 4 game. Covers loading audio, playing sounds, music, volume, spatial audio,…

@phaserjs@phaserjsInstall Skill
cameras

cameras

Use this skill when working with cameras in Phaser 4. Covers camera effects (shake, fade, flash, pan, zoom), following sprites,…

@phaserjs@phaserjsInstall Skill
curves-and-paths

curves-and-paths

Use this skill when working with curves and paths in Phaser 4. Covers splines, bezier curves, lines, ellipses, path followers,…

@phaserjs@phaserjsInstall Skill
data-manager

data-manager

Use this skill when using the Phaser 4 DataManager to store custom key-value data on game objects, listen for data change events,…

@phaserjs@phaserjsInstall Skill

More skills from other plugins.

next-bundle-optimizer
Auto-invoked

next-bundle-optimizer

Audit and reduce Next.js browser initial-load work. Use for slow route startup, oversized client bundles, duplicate browser…

nextjs5d143k
@vercel@vercelInstall Skill
migrate-radix-to-base

migrate-radix-to-base

Migrates React projects and components from Radix UI to Base UI. Use when asked to migrate from radix, move to base-ui, convert…

ui2w127k
@shadcn-ui@shadcn-uiInstall Skill
chrome-release-cls

chrome-release-cls

Given a Chrome Releases blog post URL (chromereleases.googleblog.com), extract every CVE/bug and find the underlying Gerrit CL…

electron5d124k
@electron@electronInstall Skill
taste-skill
Auto-invoked

taste-skill

tasteskill v2, the anti-slop frontend skill. Art direction for websites, distilled from a study of 247 curated gallery sites (One…

Questions about physics-matter.

Which coding agents can use physics-matter?
physics-matter installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.