How to make signal private for one instance

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

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 :slight_smile:

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

klaas | 2021-07-10 19:07

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.

IceExplosive | 2021-07-10 19:11

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.

sash-rc | 2021-07-10 20:37

:bust_in_silhouette: Reply From: Wakatta

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