Is It in the Group?
Part of the Signals and Collisions section of Coddy's Godot journey. Lesson 12 of 27.
Checking body.name works for one node. For a set of nodes, check the group:
if body.is_in_group("racers"):
print(body.name, " finished!")is_in_group() is true or false. Use it even for one node. A name changes when you rename or copy a node. A group says what the node is.
Three robots run to the finish line. Red and Blue are in the group racers, set in the scene. Bot cleans the track and is in no group.
Challenge
EasyMake the finish line print only for racers.
- In
_on_body_entered(body), put theprintinside anif. - Make the
ifaskbody.is_in_group("racers").
Press Play: the Console shows Red finished! and Blue finished!, and nothing for Bot. Then Check.
Try it yourself
extends Area2D
func _ready():
body_entered.connect(_on_body_entered)
func _on_body_entered(body):
print(body.name, " finished!")
All lessons in Signals and Collisions
Practice on your own: Godot playground