Menu
CoddyTech

Areas Notice Bodies

Part of the Signals and Collisions section of Coddy's Godot journey. Lesson 1 of 27.

An Area2D is a zone that notices what walks into it.

An Area2D needs a CollisionShape2D child. The shape sets the area's size, here the green box. Bodies walk through an area. They do not bump into it.

When a body walks in, the area sends a signal called body_entered. This zone's script listens for it:

extends Area2D

func _ready():
	body_entered.connect(_on_body_entered)

func _on_body_entered(body):
	print("Welcome to the zone!")

_on_body_entered runs each time a body enters the shape. The next lesson explains the connect line. The robot is a body, but it walks along y = 250, below the zone.

challenge icon

Challenge

Easy

Put the zone on the robot's path.

  1. The robot walks along y = 250. In _ready(), set the zone's position.y to 250.
  2. Leave the connect line as it is.

Press Play: when the robot walks in, the Console shows Welcome to the zone!. Then Check.

Try it yourself

extends Area2D

func _ready():
	body_entered.connect(_on_body_entered)

func _on_body_entered(body):
	print("Welcome to the zone!")

All lessons in Signals and Collisions

Practice on your own: Godot playground