Toggle animation Backwards and Forward with Anim component


I have an animation running over 8 seconds from A to B. I’m trying to figure out a good way to set up the anim component so that me as the user can do the following:

  1. Toggle the animation on a button, so that it runs forwards and backwards for each click.
  2. Make it so that it does nothing if user clicks while it’s in motion.

Sounds simple enough but I’ve banged my head against the state machine vs doing it by code, using speed multipliers to start and stop vs different state with triggers etc but I always end up with some silly detail of it not working the way I’d like. Just wanted to check if someon has a scenario like that that I could have a look at?


  • Björn

Something like this? Problem with stopping fbx animation on time events when animation plays in reverse - #11 by mdesign

1 Like

Thank you, that was exactly what I needed. Simple and clean!

btw, in the documentation for anim events: (Anim Events | Learn PlayCanvas) it states they should be defined in normalized time (0-1).

In my testing, they work only if defined in absolute time, and they do not trigger if animation is reversed, but that was allready reported right?

They should be normalized however they do not work for animations playing backwards at the moment: Make anim events fire for reversed anims. · Issue #3808 · playcanvas/engine · GitHub

If you can reproduce the event time bug between normalised time in a new project, that would be great

Confirmed that the user manual is incorrect and it should be in seconds. Making a fix now

1 Like

Great, sorry yes I never had time to reproduce. Good that you found it.