I am currently trying to make a tower defense game. very much a beginner. And I know there must be a better way for me to use signals in this setting. I am trying to cast a signal when the enemy gets to the end of the path, and then take damage. Calling get_parent twice seems so wrong here, but I can’t figure out how to connect the signal another way.
Thanks in advance!
game.gd
extends Node2D
var health = 20
signal end_of_path
func _on_end_of_path(enemy, damage): #connected signal
print("signal emitted")
health -= damage
print(health)
enemy.queue_free()
var called = false
func _process(delta: float) -> void:
const SPEED := 500.0
progress += SPEED * delta
if progress_ratio > 0.99 and !called: # means if called is false
get_parent().get_parent().emit_signal("end_of_path", self, damage)
called = true
print("Progress done")