Menu
CoddyTech

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_entered and body_exited: a body came in or left. Bodies are solid things, like CharacterBody2D and StaticBody2D.
  • area_entered and area_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 icon

Challenge

Easy

Two 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!")
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