I’m using godot 4.3
I am really new and I am making a snake clone, I’ve created an area2d for the food and a characterbody2d for the snake with a round collisionshape around both the food and snake and I put this function in the food scene:
func _on_food_body_entered(body: Node) → void:
if body.name == “Snake”: # Ensure the snake has the correct name
queue_free() # Free this food instance
print(“touche”) # Print to confirm the collision
And it works, when the snake touched the food,the food disapears. Following that I made a wrote a function in my game scene to spawn food around the game area:
func spawn_food():
var new_food = preload(“res://food.tscn”).instantiate()
new_food.position = new_food_position
add_child(new_food)
With this (and other stuff to determine position) the food child appears in the game, in random places, the problem is, the child doesn’t get freed when coliding with the snake like the parent, I think the child should follow the same logic as the parent so I dont know what I am doing wrong here.
Layers and mask are set to 1, and I assume the problem isn’t the collision because the parent collisionw works