0 votes

When the player hit something, I'm playing hit animation from animation_player. However when player hit something while hit animation is playing, it just ignored and play previous hit animation.

I need to stop the animation, but couldn't find any related information. How do I stop the animation and play again immediately?

in Engine by (137 points)

1 Answer

+1 vote

If you call .stop(true) on the animation player, it will reset to the start of the animation. So when you want to play the hit animation, you can call .stop(true) and then immediately call .play() to play from the start.

The true you pass to stop is telling it to reset the animation to the beginning. If you call stop without passing that, it will just pause and resume next time you call play().

https://docs.godotengine.org/en/3.1/classes/class_animationplayer.html#class-animationplayer-method-stop

by (52 points)
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.