Menu
CoddyTech

Coin Collector: Coins

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

Each of the six coins runs coin.gd, so you write it once. A coin does three things you already know:

  • It joins the group coins, so Main can count the coins later.
  • It listens to its own body_entered.
  • It frees itself when the player touches it.

The player is in the group player, set in the scene. Check for it before freeing the coin, so nothing else picks one up:

func _on_body_entered(body):
	if body.is_in_group("player"):
		queue_free()
challenge icon

Challenge

Easy

Write coin.gd:

  1. In _ready(), join the group coins and connect body_entered to _on_body_entered.
  2. In _on_body_entered(body), free the coin if the body is in the group player.

Walk over the coins. Each one should disappear.

Try it yourself

extends Area2D

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 Signals and Collisions

Practice on your own: Godot playground