Making a "hit" animation work

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

So i have a problem with the hit animation.
I can´t play the hit animation when i hit the enemy.
I have this code for the enemy (for his death):

func dead():
	vida -= 1
	if vida <= 0:
		is_dead = true
		velocidade = Vector2(0,0)
		$AnimatedSprite.play("morte inimigo1")
		$CollisionShape2D.set_deferred("disabled",true)
		$Timer.start()

and this one for the “damagebox”

func _on_damagebox_body_entered(body):
if "inimigo1" in body.name:
	body.dead()

what can i do so when i hit the enemy a “hit” animation plays?
Pls help

:bust_in_silhouette: Reply From: textile

A cool hit animation is making the player blink, this is the code:
func anime():
hide()
yield(get_tree().create_timer(0.2), “timeout”)
show()
yield(get_tree().create_timer(0.2), “timeout”)
hide()
yield(get_tree().create_timer(0.2), “timeout”)
show()
//as many times as you want