class_name Chocolate extends Node3D const COLLECT_ANIM := "collection" @onready var chocolateAnimation: AnimationPlayer = $ChocolateAnimation var _collected := false func _on_chocolate_tablet_body_entered(body: Node3D) -> void: if _collected: return if body is Walker: _give_chocolate_to(body) _collected = true func _give_chocolate_to(walker: Walker) -> void: walker.give_chocolate() reparent(walker) chocolateAnimation.play(COLLECT_ANIM) chocolateAnimation.animation_finished.connect(_finish) func _finish(animation_name: String) -> void: if COLLECT_ANIM == animation_name: # Collection is finished queue_free()