Animation stops if Loop false and speed is negative


#1

Hello Dear PlayCanvas People!

I’ve noticed, that you can’t playback an animation in one time with a negative animation speed. I do know why. The documentation says, that if loop is disabled, it will stop on the final frame, obviously the last frame of the animation is the first frame if played backwards. Therefore the animation will not start at all.

Can this be fixed ? I mean it would be helpful if you’re trying to make Loop Back and Forth Animation where you throw an event when the animation reached the final frame (animation.playing == false) which then reverses the animation speed and then plays it back and forth. Because this can not easily be achieved by checking the current and last frame of the animation, because if the first frame is something different it will “flicker”.

Someone has a better approach to this ? Or maybe fix it ?


#2

Hi Bfischlin,

Here’s a snippet of code that I use at https://www.gameskinners.com - if you click on the box in the ground to open / close, you’ll see it in action

entity.animation.play(animationName);
if(reverse)
{
    entity.animation.speed = -Math.abs(entity.animation.speed);
    entity.animation.currentTime = entity.animation.duration - 0.001;
}
else
{
    entity.animation.speed = Math.abs(entity.animation.speed);
}

#3

Thank you that hint brought me to a solution! :slight_smile: