Game dev
Saved & recent

Collision layers

Related terms: layer mask, collision matrix

Labels that decide which objects can collide with which. Every collider is put on a layer, and a matrix says which pairs of layers interact. The player's own bullets ignore the player. Pickups react only to the player.

Ignored pairs are never tested, so this is also an optimization. A layer mask applies the same filter to a raycast: "only hit walls".

Further reading
Unity: Use the layer collision matrix to reduce overlaps
player player enemy enemy shot shot pickup pickup ignored pair player enemy shot-layer query
The shot layer ignores the player and can collide with the enemy. The matrix encodes the same filter in both row and column order.

View in the full Game dev collection