See all glossary termsIn Godot, collision layers and masks are properties available to all physics nodes that filter which nodes can interact with each other. They are a very efficient way to filter physics interactions performance-wise.
While the two properties are called layers and masks, you can think of them as more of a grouping or tagging system but just for physics. Physics layers control what physics groups a node is part of, and physics masks control what physics groups a node detects.
For example, if you have a player character and a wall, you might want the player to collide with the wall but not with other players.
You can achieve this by setting the player's collision layer to 1
and the collision mask to 2
. Then, you can set the wall's collision layer to 2
and give it no collision mask (because the wall itself doesn't need to detect anything; only the player needs to detect the wall and stop when touching it).
This way, the player will detect the wall because its collision layer matches the wall's collision mask. It won't detect other players because its collision mask doesn't match the other players' collision layer.
Why are these called layers and masks?Under the hood, Godot uses binary operations to handle collision layers and masks. The physics layers and masks are encoded as whole numbers in the computer's memory. The numbers are then compared using binary operations to determine if two nodes should interact with each other. These are very efficient operations that compare the individual 0s and 1s of the binary representation of the numbers, maximizing filtering performance.This is probably where the term mask comes from, as the binary operations are often called bitmasking operations. The term layer is likely used because it's a common term in 3D modeling and game development to refer to groups of objects.
See Also
Related terms in the Glossary
school.gdquest.com - 0.3.5-2024-12-12T18:17:18.104Z-a38dc74be3238fd1ea161f4df67b95520741da9d-release