Break a Crate
Part of the Game Feel section of Coddy's Godot journey. Lesson 15 of 23.
When you walk into a crate, it disappears. Make it break into splinters instead. burst.tscn is a one shot CPUParticles2D of wooden splinters that removes itself when it is done.
Do not add the burst as a child of the crate. queue_free() removes a node with all its children, so the burst would go with the crate. Add it to the crate's parent, at the crate's position.
var burst = BURST.instantiate()
burst.position = position
get_parent().add_child(burst)
burst.emitting = true
queue_free()get_parent() is the node above the crate in the tree, the level. The burst is the crate's sibling, so it stays when the crate is gone.
Challenge
MediumWhen the player touches a crate:
- make a burst with
BURST.instantiate(), - put it at the crate's
position, - add it to
get_parent()and set itsemittingtotrue, - then remove the crate.
Try it yourself
extends Area2D
const BURST = preload("res://burst.tscn")
func _ready():
body_entered.connect(_on_body_entered)
func _on_body_entered(body):
queue_free()
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Game Feel
Practice on your own: Godot playground