Godot Collision Layer Mask Calculator: Bitmasks and Code
Name your Godot physics layers, tick which layers each object is in and which it scans, and this calculator gives you the collision_layer and collision_mask integers, a chart of which objects detect each other, the project.godot [layer_names] section and GDScript using set_collision_layer_value() and set_collision_mask_value().
How to use it
- Pick 2D physics or 3D physics, name the layers your game uses and press Next. Use Add layer for more, up to 32.
- Name each kind of object, tick the layers it is in and the layers it scans, and press Next. Use Add object for more.
- Check the summary and any warnings, then press Calculate bitmasks.
- Read the values and the Who detects whom chart, then press Copy layer names and Copy GDScript to bring the setup into your project.
Godot collision layers and masks explained
Every Godot physics object, such as Area2D, StaticBody2D, CharacterBody2D, RigidBody2D and their 3D versions, has two sets of 32 checkboxes. collision_layer is the set of layers the object is in. collision_mask is the set of layers it scans. The Godot docs put the rule in one line: object A can detect a contact with object B only if object B is in any of the layers that object A scans.
Detection is one-way. If the player scans the enemy layer but the enemy does not scan the player layer, the player's move_and_slide() stops at the enemy while the enemy walks straight through the player. A RigidBody is only pushed by objects it scans, and an Area only reports bodies and areas in layers it scans.
New physics objects start in layer 1 and scan layer 1, so everything collides with everything until you change them. That is why the generated GDScript clears both values to 0 before turning on the bits you picked.
How the bitmask numbers work
Godot stores each set as one integer where layer n is bit n - 1, so the value is the sum of 2 to the power of (layer - 1) for every ticked layer. Layer 1 is 1, layer 2 is 2, layer 3 is 4 and layer 4 is 8. The Godot docs' example of layers 1, 3 and 4 is 1 + 4 + 8 = 13, or 0b1101 in binary.
Worked example with the tool's starting setup: the player is in layer 2 (collision_layer = 2) and scans the world and enemies on layers 1 and 3 (collision_mask = 1 + 4 = 5). The coin is an Area in layer 4 that scans only the player's layer 2, so it can report the player touching it while enemies pass through it.
In code, set_collision_layer_value(layer_number, value) and set_collision_mask_value(layer_number, value) take a layer number from 1 to 32, so you never need to work out the bits by hand. You can also export a property with @export_flags_2d_physics or @export_flags_3d_physics to get the same layer checkboxes in the Inspector.
Naming layers in project.godot
Layer names live in Project Settings > Layer Names > 2D Physics or 3D Physics. Godot saves them in project.godot under a [layer_names] section with keys such as 2d_physics/layer_1="World" or 3d_physics/layer_2="Player". The names are labels only: they show up in the Inspector's layer grid and change nothing about how collisions work.
2D and 3D physics have separate names, so a game that uses both needs both sets. Plan a few layers you know you need, such as world, player, enemies, player attacks, enemy attacks and pickups, and leave the rest free for later.
Frequently asked questions
What is the difference between collision layer and collision mask in Godot?
How many collision layers does Godot have?
Do both objects need to scan each other to collide?
What number do I put in collision_mask for layers 1 and 3?
Why does everything collide with everything in my Godot game?
More free game dev tools
- Godot Input Map Generator: Godot 4 input actions for keyboard, mouse and gamepad, as an autoload or a project.godot section.
- GDScript Boilerplate Generator: Typed Godot 4 GDScript templates for player controllers, state machines, health and autoloads.
- Godot Shader Generator: Pick a 2D effect, tune its uniforms with a live preview and download a Godot 4 .gdshader.