melonjs-physics
O que ela faz
Explica o sistema de colisão integrado do melonJS e os dois motores de física opcionais, e quando cada um se encaixa. É para desenvolvedores que fazem plataformas, jogos de visão superior ou cenas com muita física.
Quando usar
- ✓Quando um desenvolvedor precisa escolher entre o sistema de colisão integrado e um motor de física completo.
- ✓Quando um objeto girando de um desenvolvedor colide como se nunca tivesse girado.
- ✓Quando um desenvolvedor precisa de raycasts ou consultas de área para encontrar objetos no mundo do jogo.
Link da skill
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-physics/SKILL.mdCopie e cole na sua IA (Claude, ChatGPT ou Cursor) pedindo para seguir as instruções.
Como usar
O jeito mais fácil: copie a mensagem e cole na sua IA. Ela lê a skill e segue as instruções.
Mensagem pronta para colar
Para Claude Code, Codex ou Cursor: rode na pasta do projeto e a skill fica instalada.
Baixe o SKILL.md e coloque na pasta de skills do seu agente.
Exemplo do que pedir para a IA
“Meu plataforma em melonJS deve usar as colisões integradas ou um motor de física? Mostre como configurar as colisões.”
5 skills novas por semana. 1 minuto de leitura.
Como funciona
A skill explica que o sistema integrado serve para a maioria dos jogos arcade, e que um adaptador de física é necessário para rotação, impactos e articulações. Depois, trata de tipos de colisão, máscaras e callbacks.
Conteúdo técnico (SKILL.md original)
Texto original do autor, em inglês, direto do GitHub.
Physics and collision
melonJS has a built-in SAT collision world and two optional rigid-body adapters. Movement, collision callbacks and spatial queries all behave differently depending on which is active — and several of the differences fail silently.
Choosing a world
| when | |
|---|---|
| built-in (default) | Arcade-style: platformers, top-down games. Fast, position-based, not Newtonian. |
@melonjs/planck-adapter |
Full rigid-body dynamics — stacking, joints, realistic restitution. |
@melonjs/matter-adapter |
Same class of thing, backed by matter-js. |
Picking one
Start with the built-in. It is the default for a reason: no dependency, the smallest bundle, and its position-based model is what most 2D games actually want — a platformer's jump arc is a designed curve, not a simulated one, and tuning gravity against a solver you are fighting is a bad afternoon.
Move to an adapter when the game needs something the builtin cannot express, and these are the usual triggers:
- Rotation that collides. The clearest signal. The builtin's SAT never reads
body.angle, so a spinning shape collides as though it never turned. See the note in Built-in world quirks below. - Torque, angular velocity, or spin from an impact. Anything that should start turning because it was hit.
- Joints and constraints — ragdolls, chains, ropes, vehicles, hinged doors. The builtin has no concept of them.
- Stacking and resting contacts. Boxes that pile up and stay put need an iterative solver. The builtin resolves each contact once per step with no iteration pass, which splits three ways. A dynamic body resting on STATIC geometry is exact, to the pixel, which is the platformer case it exists for. A body squeezed between a dynamic body and static geometry is exact too: the immovable side gets the casting vote and the other body absorbs the whole correction, so a crate shoved against a wall stops at the wall. But a body squeezed between two DYNAMIC bodies has no immovable side to defer to, so those per-pair corrections still compete and it comes to rest slightly overlapping. Three stacked 44px boxes rest flush on the floor with about 2px of overlap inside the pile, and stay there: a stable equilibrium, not jitter you can wait out or tune away.
- Believable restitution and friction, where a ball's bounce height and roll should follow from its material rather than from code you wrote per case.
Stay on the built-in when the game is grid or tile based, movement is
authored rather than simulated, collision is "did these two boxes touch" plus a
push-out, or you are shipping to a tight bundle budget. Tiled maps, Trigger
and Collectable all work on every backend, so this is not a fork in the road
for level content.
planck or matter? Both are real rigid-body engines and either will do; the adapters expose the same portable API, so a game can switch with an import change and a gravity re-tune.
- planck (a Box2D port) is the more accurate and the more predictable under
stress: better stacking, better joint behaviour, a continuous-collision
bulletmode for fast movers. It works in metres, so it has apixelsPerMeterscale to think about, and its tuning vocabulary is Box2D's. - matter-js works directly in pixels, which makes it the gentler
introduction, and its compound bodies and constraints are pleasant to author.
It is the softer solver: stacks settle less crisply and fast bodies need
subSteps.
If you have no preference and the game leans on stacking, joints or fast projectiles, take planck. If you want to be up and running with the least conversion to think about, take matter.
An adapter is an Application setting, not a plugin:
import { PlanckAdapter } from "@melonjs/planck-adapter";
const app = new Application(800, 600, {
parent: "screen",
physic: new PlanckAdapter({
gravity: { x: 0, y: 320 }, // pixels/s², default {x: 0, y: 320}
pixelsPerMeter: 32, // default 32
subSteps: 2, // default 1
}),
});
await app.init();
PlanckAdapter also takes velocityIterations (default 8) and
positionIterations (default 3). MatterAdapter takes a different set —
gravity (default {x: 0, y: 1}, matter's own convention), subSteps and
matterEngineOptions; it has no pixelsPerMeter because it already works in
pixels. subSteps is the a
Perguntas frequentes
Quando o sistema de colisão integrado basta?
A skill diz que ele serve para a maioria das plataformas e jogos de visão superior, porque é rápido e baseado em posição.
Por que objetos rotacionados colidem de forma errada?
A skill observa que o sistema integrado não lê a rotação, por isso é preciso um adaptador de física para isso.
Quais consultas ele faz?
Ele cobre raycasts e consultas de área ou de círculo para encontrar objetos.
Detalhes
Descrição original do autor
Use this skill for collision, physics bodies, movement, and spatial queries in melonJS — the built-in SAT world and the planck/matter adapters. Covers bodyDef vs Body, collision types and masks, the collision callback family and their firing rules, raycast/queryAABB/querySphere, the behaviour differences between adapters, and which one to pick for a given game. Triggers on: which physics engine, choosing an adapter, rotation collision, rotating body, torque, joints, stacking, Body, bodyDef, collision, collisionType, collisionMask, onCollision, onCollisionStart, onCollisionActive, raycast, quer
repo: melonjs/melonJS
Popularidade
- Estrelas no GitHub
- 6,4 mil
- Posição no ranking
- #14210
- Licença
- MIT
- Atualizada em
- 02/11/2026
Comentários
- …
Mais skills deste repositório
melonjs-20-migration
6,4 milAjuda seu agente a escrever código de jogo em melonJS para a versão 20 e a evitar métodos desatualizados de versões antigas, como a inicialização assíncrona obrigatória.
melonjs-3d-assets
6,4 milAjuda seu agente a carregar modelos 3D, como arquivos glTF, GLB e OBJ, em um jogo melonJS para navegador, com opções de escala e iluminação.
melonjs-3d
6,4 milAjuda seu agente a criar cenas 3D ou 2,5D em um jogo melonJS para navegador, cobrindo câmeras, malhas, luzes e profundidade, usando as regras de eixos do próprio motor.
melonjs-audio
6,4 milAjuda seu agente a adicionar efeitos sonoros e músicas a um jogo melonJS, incluindo a configuração de áudio, faixas de fundo, controle de volume e som espacial.
Skills parecidas
diffs
394 milPermite que seu agente gere um diff real e compartilhável das edições, como link de visualização ou arquivo de imagem, em vez de um resumo escrito à mão.
coding-agent
394 milAjuda seu agente a passar um trabalho grande de programação para o Codex, Claude Code ou OpenCode em segundo plano e acompanhar o andamento.
gh-issues
394 milAjuda seu agente a encontrar issues do GitHub, escolher quais resolver e abrir pull requests com correções, acompanhando os comentários de revisão.