how do i change the recipient of a signal?

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

right now in my shooter game im using this code to damage enemys:

func _process(_delta):
if $Camera3D/RayCast3D.is_colliding() and get_hit >= 1:
	var target = $Camera3D/RayCast3D.get_collider()
	if target.is_in_group("enemy"):
		emit_signal("damage", damage_value)
	get_hit = 0

and this to recive the damage:

func _physics_process(delta):
if health <= 0 and not respawning:
	respawning = true

#when on_player_damage signal is emited

func _on_player_damage(value):
health -= value

this works when there is only one enemy. but the problems start when there is 2. if i attack the 2nd enemy the first one dies. im geussing its because the signal still sends to the original enemy. how can i make it so the signal only sends to the enemy that is being hit?

:bust_in_silhouette: Reply From: jgodfrey

Here’s a similar question with a few relevant, but different, approaches to the problem…