+1 vote

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.

in Engine by (25 points)

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

1 Answer

0 votes

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.
by (3,211 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.