0 votes

I am new to godot and I'm trying to make a simple 2d top down game.
I have a level with multiple enemies (instances of the same scene).
When the player enters into one of the enemies' detection area (Area2d with collisionshape2d), the detection area emits a signal ("body entered").
This signal is connected to a method which makes the enemy attack the player.

Currently, when the player enters the detection area of one enemy, all the enemies are trying to attack the player which is not the required behavior.
What can I do so only the enemy that encountering the player will "listen" to the emitted signal from his detection area?

Thanks :)

Godot version 3.2.3
in Engine by (12 points)

Hi,
can you post code or a screenshot from your signal connection setup?

Hard to say what's wrong like that.
First, try to add some print("something") into BodyEntered function -> it should print only once if only one enemy detects the player.

If that's ok, then it's probably not collision, but the way you handle attack state and instead of putting one instance into attack, you set all enemies into it.

What can I do so only the enemy that encountering the player will "listen" to the emitted signal from his detection area?

Instead I'd suppose to "only the enemy that encountering the player (whatever it means)" acts upon a signal.

1 Answer

0 votes

Some options for you

  • Let Each enemy have their own detention area
  • When the player enters the area find which enemy is within attack range of the player
  • Player has the detection area and decides what entered bodies should do
  • Reference the parent/child node of the area that made the detection
  • debug for faulty code
by (4,604 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.