All examples · Physics · As Markdown, for AIs

Collisions with physics

What this example shows

A crate is a physics body, and it hears itself land with useCollisionWith(Floor, …, { when: 'start' }): the same line a piece with a hitbox would write, told here by the simulation, so nothing has a hitbox. A game can move from hitboxes to physics without rewriting a collision.

The layers have names, given once to the game: physicsLayers: ['world', 'crates', 'ghost']. The floor says layer: 'world', collidesWith: ['crates'], a crate layer: 'crates', collidesWith: ['world', 'crates'], and G turns every crate with setLayers('ghost', []): on a layer nothing meets, it falls through. Two bodies meet only if each one's collidesWith has the other's layer. The crates carry the tag 'crate' and the HUD counts them by it. Z drops a crate.

Starting
Starting
—