phaserjs/phaser/physics-matter
Claude Code and agent skill by phaserjs/phaser
- community
Checking that the SKILL.md file is still in the repository.
Matter Physics in Phaser 4 (Matter 0.20 and its Runner): this.matter.add (sprite, image, rectangle, circle, fromVertices, constraint, mouseSpring), shapes and PhysicsEditor data, compound bodies and sensors, collision filtering and events, the timestep, tilemap bodies, sleeping, debug drawing and the 4.3 changes. Use for rotating rigid bodies, stacking, ragdolls, chains, slopes, physics puzzles, a Matter platformer with a foot sensor, or dragging bodies. Corrects common mistakes: getDelta doesn't set the step (use runner.fps), fps.target doesn't cap the frame rate, a sleeping body ignores setVelocity, setOnCollide never fires for compound bodies. Triggers on: matter, matter.js, rigid body, constraint, joint, spring, sensor, compound body, collisionstart, PhysicsEditor, ragdoll.
Install
npx vskill@latest install phaserjs/phaser/physics-matterSKILL.md
The same SKILL.md was published earlier as phaserjs/phaser/physics-matter.
Matter Physics
Rigid-body physics with rotation, any convex or concave shape, constraints and composites. Phaser 4 bundles Matter 0.20.0 and steps it with the Matter Runner.
Source: src/physics/matter-js/ (MatterPhysics.js, World.js, Factory.js, components/, typedefs/, events/, MatterTileBody.js), and the Matter library in src/physics/matter-js/lib/. Related: physics-arcade, tilemaps, game-setup-and-config.
Quick start
Units and timing
- Positions are in pixels and angles in radians. Velocity is in pixels per step of 1000/60 ms, Matter's base delta, whatever the step size, so
setVelocityX(5)is about 300 pixels per second. - Forces are tiny:
applyForce({ x: 0.01, y: 0 })is a firm push for a 32x32 body at the default density of 0.001. gravity: { x: 0, y: 1 }is multiplied byscale(0.001). At runtime:this.matter.world.setGravity(x, y, scale),disableGravity(). Per body:setIgnoreGravity(true), orgravityScale: { x, y }in the body config, which works again since 4.3.
The step. World.update uses the Matter Runner. It steps the Engine in fixed slices of runner.delta (default 1000/60 ms) to match the real time that has passed, smoothed, and up to runner.maxFrameTime (33.3 ms) of simulation per frame. The simulation runs at the same speed at any frame rate. On a 120Hz display it steps about every other frame.
this.matter.set60Hz()andset30Hz()setrunner.delta, the same asrunner: { fps }. Before 4.3 they did nothing. ThegetDeltaconfig and World property aren't used any more: don't set them.- To step it yourself, set
autoUpdate: falseand callthis.matter.step(delta)fromupdate. It ignoresenabledandautoUpdate. - Pause with
this.matter.pause()andresume(). Slow motion:this.matter.world.engine.timing.timeScale = 0.5, ortiming: { timeScale: 0.5 }in the config. - The game's frame rate:
fps: { target: 60 }in the game config doesn't cap it.fps: { limit: 60 }does, orthis.game.loop.setFPSLimit(60)at runtime. Matter doesn't need either to run at the right speed. - Other config keys and their defaults:
src/physics/matter-js/typedefs/MatterWorldConfig.jsandMatterRunnerConfig.js. A Scene's ownphysics.matterconfig is merged over the game's.
Bodies and shapes
- Body config keys (
typedefs/MatterBodyConfig.js):label,isStatic,isSensor,density(0.001),friction(0.1),frictionStatic(0.5),frictionAir(0.01),restitution(0),chamfer: { radius },collisionFilter,ignoreGravity,ignorePointer,shape. - Game Object methods come from
components/:setVelocity,setAngularVelocity,applyForce,thrust,setBounce,setFriction(value, air, static),setMass,setDensity,setStatic,setSensor,setFixedRotation,setIgnoreGravity, the collision setters and the shape setters. setRectangle,setCircle,setPolygon,setTrapezoidandsetBodymake a new body, so friction, filters and callbacks set before are lost. Set them again.setFixedRotation()stops rotation and zeroes the angular velocity. Since 4.3,setFixedRotation(false)lets the body rotate again.- Setting
x,y,angleorscaleon a Matter Game Object moves or scales the body directly, without velocity. A negative scale on one axis, to flip it, collides correctly since 4.3.
Compound bodies and a foot sensor
A compound body is one body made of parts. Each part has the Game Object as its gameObject, and its own label, so a collision tells you which part was hit.
this.matter.bodyisMatter.Bodyandthis.matter.bodiesisMatter.Bodies. All Matter modules are onPhaser.Physics.Matter.Mattertoo.- The position of a compound body is its centre of mass.
setExistingBodysets the sprite's origin to match. - Options passed to
Body.creatego on the parent. Contacts use the parent's friction and restitution. - Attach constraints to the parent body, not to a part.
Collision events
On a Game Object, as plain strings: 'collide', 'collideActive' and 'collideEnd', with (myBody, otherBody, pair). myBody is the part of this object that was hit. This is the simplest way to react to collisions, and works for compound bodies.
On the World, using Phaser.Physics.Matter.Events: COLLISION_START, COLLISION_ACTIVE and COLLISION_END, with (event, bodyA, bodyB). bodyA and bodyB are from only one of the pairs, so loop over event.pairs:
pair.bodyAandpair.bodyBare parts, in no set order. Use.labelto tell them apart,.parentfor the whole body,.gameObjectfor its Game Object (undefined if it has none), andpair.collision.normalanddepthfor the contact.setOnCollide(cb),setOnCollideActive,setOnCollideEnd(callback getspair) andsetOnCollideWith(bodyOrGameObject, cb)(getsotherBody, pair) are set on the parent body. For a compound body they never fire, because pairs hold its parts: use the Game Object events.- The World removes its listeners when the Scene shuts down.
- Since 4.3,
body.speedandangularSpeedread during a collision event are from the end of the previous step.
Collision filtering and sensors
collisionFilter is { category: 1, mask: 0xFFFFFFFF, group: 0 } by default, so everything collides with everything.
- Two bodies with different or zero groups collide only if each one's mask includes the other's category.
nextCategoryandnextGroupuse a counter shared by every Scene, which isn't reset when a Scene restarts. Create them once, or callthis.matter.world.resetCollisionIDs()before making them increate.- A sensor (
isSensor: trueorsetSensor(true)) is never pushed, but still sends collision events, and still needs a matching filter. this.matter.intersectPoint(x, y),intersectRect,intersectRay(x1, y1, x2, y2),intersectBody(body)andoverlap(target, bodies, callback)query bodies without a collision.
Constraints, composites and dragging
- Constraints take bodies or Matter Game Objects.
lengthdefaults to the current distance.stiffness1 is rigid; low values are springy. - Composites:
stack,imageStack,pyramid,chain,mesh,softBody,carandnewtonsCradle, inFactory.js. - Drag events on the World:
DRAG_START (body, part, constraint),DRAG (body, constraint),DRAG_END (body, constraint).ignorePointer: truestops a body being dragged.
Tilemaps
- A tile with collision shapes drawn in Tiled's collision editor uses them; otherwise it gets a rectangle.
- Since 4.3, the body of a tile flipped or rotated in Tiled is flipped and then rotated with it.
tile.physics.matterBodyis the TileBody wrapper; itsbodyis the Matter body. After changing tiles, convert them withthis.matter.world.convertTiles(tiles)orthis.matter.add.tileBody(tile, options).- A body sliding along a row of tile bodies can catch on the seams between them. Give it a
chamfer. - See tilemaps for loading the map.
Sleeping
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/physics-matter/SKILL.md
Popularity
- Repository stars
- 39,633
- Repository forks
- 7,130
- 7-day trend score
- 53
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 17 May 2026, 6 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Grok Build (Cursor)
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/phaserjs/phaser/physics-matter)