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 = 2Challenge
MediumThe rolling ball takes the coin before you can. In _ready(), set the coin's collision_mask so it notices only layer 2, the player's layer. The ball should roll through the coin. Then you walk up and take it.
Try it yourself
extends Area2D
func _ready():
body_entered.connect(_on_body_entered)
func _on_body_entered(body):
queue_free()
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