How to avoid spawning near player.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By RyanJZG

So I randomly spawn and change postions of the enemies in my game, my problem is I don’t want them to spawn and change positions near the player. How do I do that? My player has an Area2D with a circle shape that is big. I want the enemies to not be in that shape.

Could you share us some of the code you have till now?

p7f | 2019-04-02 12:06

:bust_in_silhouette: Reply From: Magso

You can use distance_to

var dist = get_node("../Enemy").distance_to(get_node("../Player").get_global_pos())

if dist < get_node("Area2d/CollisionShape2D").shape.radius:
    #Don't spawn or change.