Killing one enemy kill all enemy

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

the bullet which kill all zombie

bullet.gd
func _on_bullet_area_entered(area):
queue_free()
get_tree().call_group(“zombie”,“kill_the_zombie”)

zombie.gd
extends Area2D

func _on_Zombie_body_entered(body):
get_tree().call_group(“robo_the_looser”,“player_hurt”)

func kill_the_zombie():
queue_free()


what i did :
i make one level scene in which i take one node of zombie which have 20+ instance node of zombie scene

and every bullet will generate using preload() and instance() when i press space key


the problem is that when i shoot single zombie all zombie disappear please help me .

Thanks in advance

:bust_in_silhouette: Reply From: timothybrentwood
get_tree().call_group("zombie","kill_the_zombie")

the call_group is making it so every zombie is calling kill_the_zombie() on itself. You are passed in an area upon collision so you should use that to detect which zombie the bullet hit:

bullet.gd
func on_bullet_area_entered(area):
    for zed in get_tree().get_nodes_in_group("zombie"):
        if zed == area:
            zed.kill_the_zombie()
    queue_free()

Thankyou , i am very new in
game development and even programming

pysaundary | 2021-04-28 05:42