Animation only plays once even though is on a cyclical Timer!

Godot Version

4.4.1 stable

Question

With the setup I have, as long as the enemy is touching the player, it will continuously take damage from the enemy every second due to a cyclical timer however, the animation that shows the player getting hurt will only play once. If the player moves away from the enemy’s hitbox and then touches it again, the animation will play again but only once.

I should also mention that the script that deducts life from the player is in the enemy’s script. From the enemy’s script I call the function that plays the “hurt_player” animation; and that function is in the player’s script.

Enemy Script:

@onready var _hit_box: Area2D = $HitBox
@onready var _damage_cooldown_timer: Timer = $DamageCooldownTimer

func _ready() -> void:
	_health_bar.max_value = max_health
	_health_bar.value = health
	set_health(health)

_hit_box.body_entered.connect(func(body: Node) -> void:
		if body is Player and _damage_cooldown_timer.is_stopped():
			body.health -= damage
			_player.damaged_player()
			_damage_cooldown_timer.start()
	)
	_hit_box.body_exited.connect(func(body: Node) -> void:
		if body is Player:
			_damage_cooldown_timer.stop()	
	)
	_damage_cooldown_timer.timeout.connect(func() -> void:
		_player.health -= damage
	)

Player Script:

func damaged_player() -> void:
	_hurt_player_animation.play("hurt_player")	

Again, the player takes damage consistently when touching the enemy but the “hurt_player” animation only play once.

You only play the animation when they enter the body, not on the connected timer function

Body enters:

Repeating timer:

1 Like

@gertkeno Yep, you where right. I missed adding the function call in the timeout signal. Thanks so much man, I’ve been stuck on this for more than 3 hours…lol