Menu
CoddyTech

Reach the Goal

Part of the Game Rules section of Coddy's Godot journey. Lesson 22 of 29.

A game you can lose needs a way to win. Often it is a place, like a flag at the end of a level.

The flag here is an Area2D called Goal. When a body walks in, it sends body_entered with that body. The player is in the player group, so the goal can tell it apart from other bodies:

func _on_goal_body_entered(body):
	if body.is_in_group("player"):
		$HUD/Message.text = "You win!"

The HUD has an empty Message label across the middle of the screen.

challenge icon

Challenge

Easy

Walk to the flag to win:

  1. In _ready(), connect $Goal.body_entered to _on_goal_body_entered.
  2. In _on_goal_body_entered(body), when the body is in the player group, set $HUD/Message to You win!.

Try it yourself

extends Node2D

func _ready():
	pass
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Game Rules

Practice on your own: Godot playground