Guides Physics 2D Collisions Choose What Collides With What in 2D

Physics 2D Collisions 2 min read Updated Apr 2026

Choose What Collides With What in 2D

The 2D collision matrix lets you decide which layers are even allowed to collide before gameplay code runs.

This is one of the simplest ways to keep a project manageable as it grows.

Instead of filtering every interaction in scripts, you can decide at the project level that some layers should never interact at all.

Open the Matrix

Go to:

Project -> Physics 2D Settings...

You will see a layer-to-layer grid. Each cell answers one question:

Can layer A collide with layer B?

If the answer is no, those objects do not produce normal collision behavior for that layer pair.

Why This Matters Early

A small project can get away with everything colliding with everything.

A larger one usually cannot.

Common reasons to disable interactions:

  • UI triggers should not collide with gameplay bodies
  • enemy sensors should not block movement
  • pickup triggers should not physically stop the player
  • friendly projectiles should ignore the player layer

Example Layer Plan

A simple platformer might use something like:

0  Default
1  Player
2  Enemy
3  World
4  PlayerAttack
5  EnemyAttack
6  Pickup
7  Sensor

Then your intended interactions might look like:

  • Player collides with World
  • Player collides with Enemy
  • PlayerAttack collides with Enemy
  • EnemyAttack collides with Player
  • Pickup overlaps Player as a trigger
  • Sensor overlaps gameplay layers but does not block movement

Think of It as a Project-Level Filter

The collision matrix decides whether two layers are allowed to interact at all.

It sits below your gameplay code and below one-off query filters.

That means it is different from a query layer mask:

  • collision matrix = global project rule
  • layer mask = one specific query asking a narrower question

Practical Setup Examples

Platformer

Use the matrix to keep attack layers and sensor layers separate from normal world collision.

Top-Down Action Game

Use the matrix to stop enemies from colliding with decorative triggers or interaction zones they should ignore.

Puzzle Game

Use the matrix to ensure moving puzzle pieces only collide with the layers that actually matter for the puzzle.

Where This Shows Up in Runtime Behavior

The matrix influences:

  • rigidbody collisions
  • collider contacts
  • trigger interactions

It does not replace gameplay logic, but it removes a lot of accidental complexity before gameplay code even runs.

Project File Shape

The editor stores this in ProjectSettings/lenga.json under physics2D.

Example shape:

{
  "physics2D": {
    "layerCollisionMatrix": [
      4294967295,
      4294967295
    ]
  }
}

You normally change this through the editor, not by typing those masks by hand.

A Useful Team Habit

Write down your layer meanings early and keep them stable.

Even a short note in your project docs helps:

Player = 1
Enemy = 2
World = 3
Pickup = 6
Sensor = 7

That makes debugging much easier when a collision pair feels wrong.