Menu
CoddyTech

Layers and Masks

Part of the Signals and Collisions section of Coddy's Godot journey. Lesson 22 of 27.

Bodies and areas sit on numbered collision layers. Each has two settings:

  • collision_layer: the layers it is on.
  • collision_mask: the layers it looks at. An area notices only bodies on a layer in its mask.

Both are numbers. Layer 1 is 1, layer 2 is 2, layer 3 is 4, layer 4 is 8. Everything starts on layer 1 with mask 1, so everything notices everything.

Here the player is on layer 2 and the coral ball is on layer 1. To let only the player take the coin, the coin looks at layer 2 alone:

func _ready():
	collision_mask = 2
challenge icon

Challenge

Medium

Let the coin notice only the player.

  1. The player is on layer 2. At the start of _ready(), set the coin's collision_mask so it notices only layer 2.
  2. Leave the connect line as it is.

Press Play: the ball rolls through the coin, then you walk up and take it. Then Check.

Try it yourself

extends Area2D

func _ready():
	body_entered.connect(_on_body_entered)

func _on_body_entered(body):
	queue_free()
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Signals and Collisions

Practice on your own: Godot playground