Readonlycapabilitiesadvertised capabilities; user code may branch on these
World gravity. Mutate to change at runtime. On an adapter whose bodies
have depth (AdapterCapabilities.bodies3d) it may be a
Vector3d, whose z pulls along the depth axis; a 2D adapter
keeps a Vector2d.
Back-reference to the owning melonJS world (set in init).
ReadonlynameOptional display name reported on the startup banner. Falls back to the
adapter's physicLabel, then its class name — avoid relying on the latter,
as it is mangled in minified builds. Third-party packages typically set
this to their npm package id (e.g. "@melonjs/matter-adapter").
ReadonlyphysicShort adapter identifier exposed as world.physic. User code uses
it to branch on which physics implementation is active without
importing the adapter class — e.g.
if (app.world.physic === "matter") {
// matter-only setup (constraints, etc.)
}
Convention: a single lowercase token. The first-party labels are
"builtin" (default — BuiltinAdapter) and "matter"
(@melonjs/matter-adapter). Third-party adapters should pick a
concise identifier that won't collide with future official ones.
The reserved value "none" is set on world.physic only when the
user passes physic: "none" to Application to disable physics
entirely; adapters should not use it.
Defaults to "builtin" if an adapter doesn't declare its own — keeps
legacy adapters wired in before this field was added still working.
ReadonlypixelsSpatial conversion factor between melonJS pixels and Box2D meters.
ReadonlyplanckRaw planck namespace — escape hatch for planck-specific features the portable PhysicsAdapter interface doesn't cover (joints, compound fixtures, native queries, etc.).
Saves you from adding a transitive import * as planck from "planck"
just to reach the factories you need:
const bodyA = a.body as PlanckAdapter.Body;
const joint = new adapter.planck.RevoluteJoint(
{ collideConnected: false },
bodyA,
b.body as PlanckAdapter.Body,
bodyA.getPosition(), // the pin, a world point in meters
);
adapter.world.createJoint(joint);
Game code that touches adapter.planck.* is planck-only — it will
not work under any other physics adapter. Use the
PhysicsAdapter methods for anything that should stay
portable.
ReadonlyurlOptional URL (npm / homepage / repo) reported on the startup banner. Convention matches the debug-plugin's startup line.
ReadonlyversionOptional package version reported on the startup banner. Set this when shipping the adapter as a separate npm package so users can tell which version is wired in at a glance.
The underlying planck world; exposed for advanced use cases.
Register a body with the simulation. Returns an opaque handle that
becomes renderable.body. Each adapter chooses its own concrete
body type — see the class doc for the convention. Like the builtin
Body constructor, it sets renderable.isKinematic to false, so the
renderable takes part in physics and receives pointer events.
Prefer the declarative path. Set renderable.bodyDef and call
Container.addChild(renderable) — the container auto-invokes
addBody AND inserts the renderable into the world's broadphase
(QuadTree) in one atomic step. Direct calls to addBody only
register the body with this adapter; they do NOT add the renderable
to the world's container hierarchy, so the broadphase won't return
it as a collision candidate. A body registered via direct addBody
without a matching addChild will integrate (velocity, forces) but
never collide.
Make a joint between two bodies: what world.addJoint() calls, which
game code uses instead. A "hinge" is a planck RevoluteJoint, a
"rope" a RopeJoint, a "weld" a WeldJoint and a "slider" a
PrismaticJoint. Made during a step (from a collision handler), the
joint takes effect once the step ends: planck refuses to change its
world while it steps.
what to join, and how, in pixels and radians
the planck joint
Optionalpoint: Vector2dOptionalpoint: Vector2dApply an angular impulse (Δω = τ / inertia).
Called when the adapter is being torn down; release native resources.
Read absolute rotation angle (radians). Returns 0 if not tracked.
Read angular velocity, in the same unit. Returns 0 if not tracked.
Adapter-side debug surface: the body's AABB in renderable-local
pixel coordinates. Planck computes fixture AABBs in world meters;
we union them, convert to pixels, then subtract renderable.pos
so the debug plugin (which translates to renderable origin before
drawing) gets local-space bounds.
the renderable whose body bounds to read
destination Bounds (filled in place, also returned)
Adapter-side debug surface: the body's collision shapes in renderable-local coordinates, at the body's current rotation.
The authored def.shapes are the pose the body was created with;
rotation lives in the physics body, not in them. Returning them
unrotated made anything reading this — the debug overlay most visibly —
describe a spinning body with an axis-aligned shape. Read-only.
the renderable whose body shapes to read
Read the body's current velocity cap (mirror of
setMaxVelocity). Returns plain {x, y} so callers don't
need to import a vector type. A body with no cap reports Infinity
on both axes; a builtin Body always has one, 490 by default. Optional — adapters that don't implement velocity caps
omit this method.
Portable velocity / force / position API. Every adapter implements
these by routing to its native engine. Use these instead of
mutating the body handle directly when writing adapter-agnostic
code. They act on the live body, which a renderable has once it is in
the world: call them from its onActivateEvent(), which runs after the
body is built, or later, never from its constructor.
Optionalout: Vector2dWhether the body has at least one active contact with a surface below it (collision normal pointing up). Capability-gated by AdapterCapabilities.isGrounded. melonJS extension — Matter has no direct equivalent and the MatterAdapter implements it by scanning active pairs each call.
Whether planck has put the body to sleep: a dynamic body at rest,
which it leaves out of the simulation until a contact, a force or a
velocity wakes it. false for a static or kinematic body (planck keeps
a static body "not awake" from the start) and for a renderable this
adapter does not know.
the renderable whose body to read
true while the body sleeps
Spatial queries.
raycast is capability-gated by AdapterCapabilities.raycasts.
Adapters that don't support it may omit the method entirely
(typeof adapter.raycast === "function").
queryAABB is mandatory — every adapter must support a region query
(a broadphase walk is already needed for collision detection, so
exposing it costs nothing).
Unregister a body. Called automatically when Container.removeChild
detaches the renderable; direct calls are the inverse of a direct
addBody (rare — use removeChild for the normal lifecycle).
Remove a joint PlanckAdapter.addJoint made: what
world.removeJoint() calls. A joint already gone, with one of its
bodies, is ignored.
the planck joint
Set angular velocity: radians per step, per second on planck and Rapier. A Vector3d is a turn about each axis, for an adapter that turns bodies in 3D; a number turns about Z, as in 2D.
Toggle a body between solid and sensor mode. A sensor still fires
collision events (onCollisionStart / onCollisionActive /
onCollisionEnd) but the engine does not push the bodies apart on
contact — useful for one-way platforms, trigger zones, ground-snap
ground assists, etc.
Adapters without a native sensor flag emulate by toggling the
collision mask between its previous value and NO_OBJECT.
Runtime body-property mutators. Each maps to the corresponding
BodyDefinition field and lets game code change a body's
physical properties without re-creating it. Adapter implementations
route to their native engine (BuiltinAdapter writes to the Body
handle; MatterAdapter calls Matter's Body.set* helpers). They act on
the live body: what a body starts with goes in its
BodyDefinition, and what is set on it from the start goes in
the renderable's onActivateEvent(), which runs after the body is
built, each time it enters the world.
Set the body's velocity. A Vector3d also sets it along the
depth axis on an adapter whose bodies have depth
(AdapterCapabilities.bodies3d); a 2D adapter reads x and y
only. The same holds for applyForce, applyImpulse and
setPosition.
Advance the simulation by one frame. Called from World.update(dt).
Copy physics-engine body positions back to renderable.pos and
rotations to the renderable's transform. Called after step
each frame. Adapters that mutate the renderable directly during
step (e.g. BuiltinAdapter) may leave this a no-op.
Replace the body's collision geometry without re-creating the body.
StaticcreateCreate an adapter, the same way for every adapter: wait for
PlanckAdapter.load, then construct it. Here that is the same as
new PlanckAdapter(options), which stays supported.
Optionaloptions: PlanckAdapterOptions
the constructor's options
the new adapter, an instance of the class create is called on
StaticloadResolves once the adapter can be constructed. planck is plain JavaScript, loaded with this package, so this resolves
at once; it is here so every adapter has the same
PhysicsAdapterClass API, and code written as
await PlanckAdapter.create() reads the same as for one that loads
WebAssembly first.
a resolved promise
melonJS physics adapter wrapping planck.js (https://piqnt.com/planck.js/).
Planck is a JavaScript/TypeScript port of Box2D 2.3.0 — a mature, battle-tested rigid-body simulator with continuous collision detection, sleeping bodies, and joint constraints. This adapter implements the full PhysicsAdapter interface so the same game code that runs on the built-in SAT physics also runs under planck — with the upgrade in capabilities Box2D brings (CCD for fast-moving bodies, restitution- based stacking, real rotational dynamics).
Box2D operates in meters / seconds / radians internally. melonJS stays in pixels for positions and radians for angles; the adapter handles the spatial unit conversion through PlanckAdapterOptions.pixelsPerMeter (default
32). Times are passed through directly (planck expects seconds, the adapter divides the incoming milliseconddtby 1000).Example