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

When the player touches a crate:

  1. make a burst with BURST.instantiate(),
  2. put it at the crate's position,
  3. add it to get_parent() and set its emitting to true,
  4. 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()
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