Skip to content

Collision layers

Collision layers control what collides with what. Here the same red bodies rain onto two shelves that differ only in their layer: on the left they hit a blue shelf — a different layer — and pile up on it; on the right they hit a red shelf — their own layer — and fall straight through to the floor.

Drag to orbit

Loading physics…
Same red bodies, two shelves. Blue (different layer) catches them; red (same layer) lets them through.

Define layers when you create the world. Each layer lists which layers it collidesWith:

const world = await World.create({
layers: {
ground: { collidesWith: ["red", "blue"] },
red: { collidesWith: ["ground", "blue"] }, // not "red" → red passes through red
blue: { collidesWith: ["ground", "red"] }, // not "blue" → blue passes through blue
},
});

Then assign each body to a layer by name:

world.createBody({ type: "dynamic", shape: Shape.box({ halfExtents: [0.4, 0.4, 0.4] }), layer: "red" });
world.createBody({ type: "dynamic", shape: Shape.sphere(0.45), layer: "blue" });

If you omit layers, jolt-ts uses a sensible default table with static and moving. See the Collision layers guide for broad-phase layers and numeric layer ids.