Lock a character into an animation

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

I have a Sprite node that uses animation strips and an AnimationPlayer node that controls the animations. I have a strip 22 frames long, for the attack animation, and I want my character to be locked into the animation for the first 8 frames of the strip, meaning that no matter how much they press jump or try to move, they will still be attacking these 8 frames. After that, the player should be able to move again. How can I do that?

For clarity: an animation strip is a single .png file that contains different frames of the animation. If I had separate .png files, i would have used AnimatedSprite.

selamba | 2019-11-18 15:10

:bust_in_silhouette: Reply From: thirite

You’ll probably want to use ‘actor states’. When the character begins an attack, add the attacking state to the list of active actor states (this can be done a multitude of ways, the simplest probably being a dictionary). When the character hits the frame the attack de-facto ends on, OR is interrupted mid-attack, set the attack state back to off. When checking if the player is able to perform actions like jumping, moving, etc. first check that the current blocking states are not active.