What it does
Every object in the 3D world has a collision shape. By default it is a box the size of its mesh: the engine's meshes
are unit-sized and scaled, so the box is simply the object's scale on each axis. Where that is wrong, you give the
object a shape as spawn data, or later with shape(h, …): a sphere, a box of another size, or one moved off the
origin, such as a character model's box that sits on its feet rather than round its middle. With model-3d composed,
a loaded model offers a box built from its own parts, and a shape the game gives still wins.
Rules name two tags. on calls back for every overlapping pair each fixed step, after the game's own steps and after
physics-3d, and solid keeps one kind of thing out of another by moving it along the axis where they overlap least.
The callback receives a contact: the side of the first object the second is against (left, right, bottom, top, back or
front, with y up) and how deep. A player whose contact with the floor is 'bottom' is standing on it, which is all a
simple 3D platformer needs to know.
Because the calls match the 2D pack's (on, solid, overlaps, test, contact, raycast), rules written for a
2D game read the same in 3D, with a z added. Rules belong to the scene that made them and leave with it, and destroying
either object inside a callback is safe: the pair is not separated, and the object meets nothing else that step.
Features
- The same calls as 2D —
on,solid,overlaps,test,contactandraycast, ongame.collide. - Boxes and spheres — a box from the mesh's scale by default, or
shape,size,radiusandoffsetas spawn data, in the object's own units so its scale multiplies them. - Six-sided contacts — which face of the first object the second touches, and how deep, read before separation.
- Solid separation — push the first object, the second or both, along the shallowest axis.
- Raycasts — the nearest object along a ray within a distance, optionally of one tag, with the hit point and the distance.
- Model boxes — with
model-3d, a loaded model's box comes from its parts with no spawn data at all. - Scene-scoped rules — rules leave with the scene that made them.
Good for
- 3D collectathons and platformers — coins and gems to pick up, floors to stand on and walls to stop at, without a physics engine.
- 3D shooters — shots against enemies, and a raycast for hitscan weapons and lines of fire.
- Triggers and zones — doors, checkpoints and level exits in any 3D game.
- 3D runners and lane games — obstacles and pickups along the track, tested by tag.
- A 2D game moving to 3D — its collision rules carry across under the same names.
Make it yours
There are no pack options: the shapes and the rules are the configuration. Give each kind of object the shape that matches what the player sees, set an offset for models whose origin is at their feet, and choose for each solid rule which side moves.
Two different uses: a coin-collecting platformer where the hero has a size: [0.6, 1.8, 0.4] box lifted by
offset: [0, 0.9, 0], walls are solid, and a 'bottom' contact with a platform marks the hero as grounded; and a
3D arena shooter where enemies are spheres, shots use on rules, and a raycast from the player picks the first enemy
in the line of fire.
A quick look
Pickups, walls, crates that push each other, a sphere and a hero whose box sits on its feet:
game.collide.on('player', 'coin', (p, coin) => { coin.destroy(); score += 1; });
game.collide.solid('player', 'wall'); // keep the player out of walls
game.collide.solid('crate', 'crate', { push: 'both' });
game.spawn({ id: 'ball', mesh: 'sphere', x, y, z, tags: ['ball'], collide: { shape: 'sphere' } });
game.spawn({ id: 'hero', model: 'hero', x, y: 0, z, tags: ['hero'], collide: { size: [0.6, 1.8, 0.4], offset: [0, 0.9, 0] } });
const hit = game.collide.raycast(x, y, z, dx, dy, dz, 50, 'enemy'); // nearest along the ray, or null
Works with
core-3d— includes this pack, so most 3D games have it already.physics-3d— for things that need mass, gravity and spin; these rules run after it.model-3d— gives loaded models a box built from their parts.collision— the 2D version; a game composes one or the other, since both aregame.collide.
Good to know
- Boxes stay upright: a turned box is tested as if it were not turned. For turned boxes that rest on each other, use
physics-3d. solidseparates a sphere as its bounding box, andraycasttests a sphere as its box.- Every pair of a rule's two tags is tested each step, so rules suit tens to hundreds of objects, not thousands.
- It is positional only:
solidmoves things apart and never changes a velocity your game keeps.






