extends Node2D const GrassEffect = preload("res://Effects/GrassEffect.tscn") func destroy_effect(): var grass_effect = GrassEffect.instance() # We add the effect to the parent and not to the grass itself since # we're going to free the current node later. # The better way to do it is to add the animated sprite in the same scense # as the grass statically and just play the animation here and disable its # interaction with the world such as hurt box # The parent in this case is a YSort node which makes the effect follow the # ysort rules get_parent().add_child(grass_effect) # set the position of the effect to the global_position of the current grass grass_effect.global_position = global_position func _on_HurtBox_area_entered(_area): destroy_effect() queue_free()