How do I check the distance of my player to an enemy?
And when the player gets close to the enemy, The enemy starts throwing something?
Sorry my english is not so good
Can someone help me, please? :D
Assuming you are working with 2d:
var distance2Hero = enemy.get_global_pos().distance_to(hero.get_global_pos());
Okay thank you, This will help me a lot.
You can also get more basic math in the docs:
And may be better to put the distance detection in the object that is going to react to it (but that depends on the design, of course).
+1 from me @eons
If you want something to happen when the player gets within a certain distance from an object attach an area to the player and connect the body_enter-signal. That way you don't need to check the distance every frame. The physics engine is much better at checking distances than such a check in a script.