Menu
CoddyTech

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 icon

Challenge

Medium

Make a crate burst into splinters.

  1. In _on_body_entered, make a burst with BURST.instantiate() and put it at the crate's position.
  2. Add it to get_parent() and set its emitting to true.
  3. Then remove the crate.

Press Play and walk into a crate: splinters fly where it was. Then Check.

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()
quiz iconTest yourself

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