0 votes

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/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 onAnimatedSpriteanimationfinished() signal:

   func _on_AnimatedSprite_animation_finished():
       ouched = false

How do I fix this?

in Engine by (38 points)
edited by

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

1 Answer

0 votes

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 onanimationfinished(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.

by (380 points)
edited by

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?

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.