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

Make the basket notice the falling stars.

  1. The stars are areas, not bodies. In _ready(), connect area_entered in place of body_entered.
  2. Keep _on_star_caught as the function.

Press Play: the Console shows Caught a star! twice, once per star. Then Check.

Try it yourself

extends Area2D

func _ready():
	body_entered.connect(_on_star_caught)

func _on_star_caught(star):
	print("Caught a star!")

All lessons in Signals and Collisions

Practice on your own: Godot playground