A Door That Opens
Part of the Signals and Collisions section of Coddy's Godot journey. Lesson 16 of 27.
To free another node, call queue_free() on that node:
$Door.queue_free()This script is on Main, the root of the scene. A plain queue_free() would free Main and every node in the game with it.
The amber door is a StaticBody2D, a solid body that never moves, like the walls. You cannot walk through it until it is freed.
Challenge
EasyOpen the door when you step on the green plate.
- Main already listens to the plate. In
_on_plate_body_entered, replacepass. - Free the
Doornode.
Press Play and step on the plate: the door is gone and you walk through. Then Check.
Try it yourself
extends Node2D
func _ready():
$Plate.body_entered.connect(_on_plate_body_entered)
func _on_plate_body_entered(body):
pass
All lessons in Signals and Collisions
Practice on your own: Godot playground