Godot:Physics
lastmod 2022-07-03created 2022-07-032 edits
Collision layers and masks
One of the most powerful but frequently misunderstood collision features is the collision layer system. This system lets you build up complex interactions between a variety of objects. The key concepts are layers and masks. Each CollisionObject2D has 20 different physics layers it can interact with.
Let's look at each of the properties in turn:
- collision_layer
- This describes the layers that the object appears in. By default, all bodies are on layer
1.
- collision_mask
- This describes the layers the body will scan for collisions. If an object isn't in one of the mask layers, the body will ignore it. By default, all bodies scan layer 1.
These properties can be configured via code, or by editing them in the Inspector (Inspecter).
Keeping track of what you're using each layer for can be difficult, so you may find it useful to assign names to the layers you're using. Names can be assigned in 프로젝트 설정 -> Layer Names (Project Settings -> Layer Names).