So, i managed to get the collision and damage working properly, but my problem is when i queue_free it doesnt get rid of the sprite2D, anyone have any advice ?
trying to call queue free on its sprite2D gave me an error. so im kinda confused on how im supposed to do it.
If you share code, please wrap it inside three backticks or replace the code in the next block:
func _on_area_entered(area: Area2D) -> void:
print("This is the Otherpart:",area, "and its damage is:", area.Damage )
var damage = area.Damage
Health = Health - damage
if Health <= 0:
print("SOMETHING ABOUT A TREE FALLING ")
self.Sprite2D.queue_free()
self.queue_free()
I am no pro at godot so maybe i am wrong but what i would try to do is when the health reaches zero (or less cuz sometimes it can happen that it goes below zero, atleast in my games) you set visibility to false by using:
visibility = false
Or something like that.
But that only implies if the code is in the tree sprite, if its not you will have to call out the tree sprite and then set visibility to false.
! As i said before im not that good at gdscript so if im wrong please forgive me !
the problem was quite stupid - i put the script inside a child of the tree (hurtbox) and not the actual tree. so of course it didnt delete the sprite2D(another child) sorry yall.
it was a dumb mistake on my part - i just figured it out, sorry for wasting your time. the problem was that i had a script inside of a child trying to delete another child using self.