0 votes

Hello! I'm a beginner and I'm making an RPG-type game to test out the engine.

I have an Area2D around the player to detect when an enemy is close enough to reach and attack, and I have another, bigger Area2D around the enemies to detect when the player is nearby and start following/attacking him

My problem:
I made it so the enemies spawn at random coordinates(when one enemy dies, another is spawned), and sometimes they spawn too close to the player and it doesn't detect the bodyentered and bodyexited because the body is already inside. So the enemies don't follow me and I can't attack them.

Any ideas on how I can fix this?

in Engine by (12 points)

Can you show your script so that I can help please?

1 Answer

+2 votes

Area2D has a method for getting all overlapping areas. Just call it when the enemy is spawned and check if the one of the areas it overlaps is the player's.

by (8,150 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 Frequently asked questions and 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 [email protected] with your username.