Areas Meet Areas
Part of the Signals and Collisions section of Coddy's Godot journey. Lesson 6 of 27.
Godot's nodes come with signals built in. An Area2D has four you will use often:
body_enteredandbody_exited: a body came in or left. Bodies are solid things, likeCharacterBody2DandStaticBody2D.area_enteredandarea_exited: another area came in or left.
An area never sends body_entered for another area. The falling stars are areas, so the basket needs area_entered:
func _ready():
area_entered.connect(_on_star_caught)The function gets the area that came in, so it takes one value, like _on_body_entered(body). You can name it anything.
Challenge
EasyTwo stars fall into the basket, but the Console stays empty. The basket listens to the wrong signal. Make it print Caught a star! for each star.
Try it yourself
extends Area2D
func _ready():
body_entered.connect(_on_star_caught)
func _on_star_caught(star):
print("Caught a star!")
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Signals and Collisions
2Signals
Areas Meet AreasYour Own SignalSignals With ValuesAnother Node's SignalListen to Your SignalPractice on your own: Godot playground