What it does
game.attach.to(child, parent, offset) gives the child a local pose: a position, yaw, pitch and roll relative to the
parent. Each step the whole chain is composed, parents before children in one pass, into the world pose the rest of
the engine already understands. Nothing else has to know an object is attached: collision, queries, culling and the
renderer see an ordinary object in an ordinary place. Chains nest to any depth.
Scale is not inherited by default, because a crate's size should never inflate whatever rides on it. Turn on
inheritScale and the child's scale becomes its own times the parent's, per axis, so a parent stretched tall makes a
tall child. Its offset then moves into the parent's units, { y: 1 } meaning one parent-height up, so it stays in
place on a parent that resizes instead of sliding off it.
face lays a child on one face of the parent's box, top, bottom, left, right, front or back, centred and
turned to face outwards, with lift keeping it a hair clear of the surface so the seam never flickers. Together with
inheritScale that is a whole animation layer: tween the parent's position and scale, and the plate on top slides,
pops, spins and shrinks with it, with no more code. When a parent dies, its children are left standing where they
were, which is what a game usually wants from a destroyed carrier.
Features
- Local poses — position, yaw, pitch and roll relative to the parent, changed later with
offset. - Ordinary objects — attached objects collide, cull, query and draw like any other.
- Chains of any depth — composed parents first in one pass, with a cycle capped rather than hanging the game.
- Opt-in scale inheritance — per axis, with the offset in the parent's units so it stays put as the parent resizes.
- Plates on faces —
faceandliftlay labels, numbers and borders flat on a box without depth flicker. - Safe detaching —
detachand a parent's death both leave the child where it is in the world. - Walk the tree —
parentOf,childrenOfand a livecount.
Good for
- Vehicles with turrets and riders — a turret on a tank, a gunner on a jeep, a camera on a mount.
- Characters holding things — a weapon in a hand, a hat on a head, a lantern on a belt.
- 3D puzzle tiles — a bevelled tile wearing its number on top, sliding and popping as one, in the style of 2048.
- Card and board games in 3D — a card and its border, a counter and its symbol.
- Labelled props — crates, signs and buttons with a plate on a face.
- Scenes built from parts — lamps with their lights, furniture with its fittings, moving together.
Make it yours
There is nothing to configure when the pack is composed; every choice is per attachment. A rigid rider on a vehicle
takes a world-unit offset and no scale inheritance, so the vehicle can grow without stretching its gunner. A puzzle
tile takes face: 'top' and inheritScale: true, so a single tween of the tile's scale pops its number too. A
turret whose base turns flat while its barrel elevates is two objects, the barrel attached to the base.
A quick look
A tile with its number on top, animated by tweening only the tile:
const body = game.world3d.spawn({ mesh: 'roundedBox', sx: 0.96, sy: 0.26, sz: 0.96, color: tint });
const face = game.world3d.spawn({ mesh: 'roundedPlane', texture: 'nums', textureFrame: n });
game.attach.to(face, body, { face: 'top', inheritScale: true });
game.tween.to(body, { x, z }, { duration: 0.13 }); // slide
game.tween.to(body, { sx: 1.15, sy: 1.15, sz: 1.15 }, { yoyo: true, loop: 1 }); // merge pop
Works with
core-3d— includes it, so most 3D games have it already.world-3d— required; the objects it attaches.tween— animate the parent and the whole assembly follows.aim-3d— a turret base and barrel that aim separately while staying joined.model-files-3d— for a loaded model whose parts already share an origin and move together without this.
Good to know
- Chains compose on the fixed step, so a very fast parent can show a hair of separation between steps.
- There is no attaching to an individual bone or part of a model yet.
faceuses the parent's bounding box, which suits a label on a crate but not a sticker on a ball.- Scale inheritance multiplies scales and does not shear, so a child rotated inside a stretched parent scales along its own axes.






