Hi,
so in my game I have areas that will damage whoever enters them (players, AI, ...)
I do use collision layers to make sure that only players and AI, and so on, are detected.
But I still want to make sure, that whatever entered the trigger actually has a damage method. (in case I forget to configure the layers)
So right now I am doing:
func _on_body_entered(body):
if body.has_method("_on_take_damage"):
body._on_take_damage(damage)
I was wondering if this is the best way to do this.
Especially, I wondered about the performance of has_method()
Another way of doing it would be:
func _on_body_entered(body):
if body.is_in_group("damage"):
body._on_take_damage(damage)
Perhaps is_in_group()
is faster than checking has_method()
?
I would like to know what the best way of doing this might be, perhaps something else I haven't considered yet?
Thank you.