im trying to make an enemy take damage when the players sword area interacts with the enemy. My approach to doing this was using custom signals, but for some reason, it seems like it isnt connecting.
heres my relevant code
Player
signal enemy_hit
func _on_sword_area_body_entered(body):
if body.is_in_group("enemy"):
emit_signal("enemy_hit")
Enemy
@onready var player = $"../Player"
var health = 100.0
func _ready():
player.connect("enemy_hit", handletakedamage)
func handletakedamage():
health -= 20
print(health)
I would suggest a different design, when the sword hits the enemy call the take damage function directly instead of the signal.
You could make it better if you used OOP and had a base class that can take damage, e.g. class_name Hittable, then extend the Hittable class to make enemies and other items that could be destroyed.