Who Walked In?
Part of the Signals and Collisions section of Coddy's Godot journey. Lesson 3 of 27.
The area passes the body that came in to your function. That is the body in _on_body_entered(body). It is the node itself, so you can read anything on it.
body.name is the name of the body that walked in:
func _on_body_entered(body):
print(body.name)A plain name is the zone's own name, because the script is on the zone.
Two bodies cross this zone: you, the Player, and an amber Rover that rolls through on its own.
Challenge
EasyWhen a body walks into the zone, print its name followed by entered the zone. The Console should show:
Rover entered the zonewhen the rover rolls throughPlayer entered the zonewhen you walk in
Try it yourself
extends Area2D
func _ready():
body_entered.connect(_on_body_entered)
func _on_body_entered(body):
print("Something entered the zone")
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