My damage animation won't play

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

I have a platformer game and I’m currently working on the player’s melee combat with a sword.
Currently I’m working on the enemies. This is the code for the enemy when it gets hit:
``
func lose_health(amount):

    ouched = true	
    $AnimatedSprite.play("Ouched")
    $AnimatedSprite/AnimationPlayer.stop()
    $AnimatedSprite/Bite_area/bite_area_left.call_deferred("set_disabled", true)
    $AnimatedSprite/Bite_area/bite_area_right.call_deferred("set_disabled", true)
        vel = Vector2(0, 0)

``
I noticed that the problem was that it doesn’t play the “Ouched” animation, despite of me adding the _on_AnimatedSprite_animation_finished() signal:

   func _on_AnimatedSprite_animation_finished():
       ouched = false

How do I fix this?

Another error that occured: the enemy won’t be able to attack after the lose_health() function happens.

owlisGODOT | 2020-06-16 15:44

:bust_in_silhouette: Reply From: MaaaxiKing

You have to set a signal on the AnimationPlayer, not on the AnimatedSprite. Or do both AnimatedSprite and it’s child, the AnimationPlayer, have the same name? In the inspector, click on the AnimationPlayer (we assume its name is AnimationPlayerOuched). On the right, you have to click on the Node tab, then you are in the Signals Tab. Then you click on_animation_finished(anim_name: String) and connect it to the root node’s script or to that script you want for example the animated Sprite and write everything you wrote into _on_AnimatedSprite_animation_finished() into this new signal function.

They both don’t have the same name. The AnimationPlayer also just disables and enables an Area2D’s two collision shapes to sync with it’s attack animation (hopefully that makes sense). Also, what kind of signal do I have to set?

owlisGODOT | 2020-06-17 06:13

I added something to the answer, so first look there and then the following bold lines. This way you will learn more about using Godot ;D
But if you want to have an animation on a sprite you either have a Sprite with an AnimationPlayer or an AnimatedSprite without an AnimationPlayer. An animated Sprite with an AnimationPlayer is just too much and it doesn’t make sense.

MaaaxiKing | 2020-06-17 09:19