I am making 2D top-down view game and I would like the player to be able to cancel certain animations while they are playing.
Let’s assume I have an idle animation and a simple animation of swinging a sword. Idle animation does nothing but sets the sword rotation to 0 degrees. Swinging animation rotates the sword from 0 to 90 degrees.
I would like to be able to cancel the sword swing animation at any time. The problem is for smooth transition between animations I would need to start the backswing animation with the same rotation of sword as in the swing animation at the moment when it was interrupted.
So I’ve prepared backswing animation which was mirrored swing animation: it rotates sword from 90 to 0 degrees.
I’ve tried using blending tree to blend between those two animations and it worked well unless the input which cancelled animation occured after half of swing animation time: the backswing animation only played for the remaining half of animation time and it ended before reaching the 0 degree rotation, which caused sword to jump.
I thought of starting the backswing animation at frame in which sword rotation is the same as it was when the swing animation was interrupted, but for this I would need to be able to set transition offset of backswing animation dynamically, depending on the moment of interrupting swing animation.
So my question is: Is there any way to set the offset of transition dynamically by script? Or is there any other way to achieve smooth transition if the starting position of next animation needs to be based on interrupted frame of current animation?