melonjs-physics
하는 일
melonJS에 내장된 충돌 시스템과 선택 가능한 두 가지 물리 엔진, 그리고 각각 언제 맞는지 설명합니다. 플랫포머, 탑다운 게임, 물리 중심 장면을 만드는 게임 개발자를 위한 스킬입니다.
사용하는 경우
- ✓개발자가 내장 충돌 시스템과 전체 물리 엔진 중 하나를 골라야 할 때.
- ✓개발자의 회전하는 오브젝트가 전혀 회전하지 않은 것처럼 충돌할 때.
- ✓개발자가 게임 월드에서 오브젝트를 찾기 위해 레이캐스트나 영역 쿼리가 필요할 때.
스킬 링크
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-physics/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“제 melonJS 플랫포머는 내장 충돌을 써야 하나요, 아니면 물리 엔진을 써야 하나요? 충돌 설정 방법도 보여 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
스킬은 내장 시스템이 대부분의 아케이드 게임에 맞고, 회전, 충돌 반응, 조인트에는 물리 어댑터가 필요하다고 설명합니다. 그다음 충돌 유형, 마스크, 콜백을 다룹니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 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
자주 묻는 질문
내장 충돌 시스템으로 충분한 경우는 언제인가요?
빠르고 위치 기반이라 대부분의 플랫포머와 탑다운 게임에 맞는다고 스킬은 말합니다.
회전하는 오브젝트는 왜 잘못 충돌하나요?
내장 시스템은 회전 값을 읽지 않으므로, 회전을 처리하려면 물리 어댑터가 필요하다고 스킬은 설명합니다.
어떤 쿼리를 실행할 수 있나요?
레이캐스트와 영역 또는 원형 쿼리로 오브젝트를 찾는 기능을 다룹니다.
상세 정보
작성자의 원본 설명
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
인기도
- GitHub 스타
- 6.4k
- 순위
- #14210
- 라이선스
- MIT
- 업데이트
- 2026. 11. 2.
댓글
- …
이 저장소의 다른 스킬
melonjs-20-migration
6.4k에이전트가 melonJS 20 버전에 맞는 게임 코드를 작성하고, 필수 비동기 시작 방식 등 이전 버전의 오래된 메서드를 피하도록 돕습니다.
melonjs-3d-assets
6.4k에이전트가 glTF, GLB, OBJ 같은 3D 모델 파일을 melonJS 브라우저 게임에 불러오고, 크기와 조명 옵션을 설정하도록 돕습니다.
melonjs-3d
6.4k에이전트가 melonJS 브라우저 게임에서 카메라, 메시, 조명, 깊이를 포함한 3D 또는 2.5D 장면을 엔진 고유의 축 규칙에 맞게 만들도록 돕습니다.
melonjs-audio
6.4k에이전트가 melonJS 게임에 효과음과 배경 음악을 추가하고, 오디오 설정, 음량 조절, 공간 음향까지 다루도록 돕습니다.