Jump to content

How to reverse animate key framed animation ?

Recommended Posts

Hi All,


I'm new here, So first of all, Kudos to all working in BJS. I'm impressed. And Kudos to the community, as I can see it is a very active community.

Coming to my problem, I have a babylon file, which contains a set of meshes, each having its own key-framed animations. After a lot of trial and error, I could animate them using

 scene.beginAnimation(mesh, 1, 100, false, 0.6, function() {});

And Iam not sure what values I need to give for speedratio, I tried with 1 and couple of other numbers and right now on 0.6.  Yay ! now it is working. It Played.


Now I have two problems or worries,

1. I had to cycle through a loop to animate the each of these meshes found inside this file, while I have attached them all into one parent (empty) node, so that I thought if I can say BeginAnimation on that mesh, the rest of the child will play the keyframes... but nothing happened... so I had to end up cycling through the whole set of meshes in the scene and animate them if the the names match.

2. Now I tried to reverse the animation cycle, to play it backwards, all it does is jumps back to the first frame. I tried different way, I gave different combinations like below, changed from as 100, and to as 1, changed speedratio as -0.6, but no effect.

 scene.beginAnimation(mesh, 100, 1, false, -0.6, function() {} );

looking for some enlightenment on both of these. 


Thanks and Keep up the good work.


Link to post
Share on other sites


I searched everywhere before I posted it here. Couldn't find any clear solution for it. 

Honestly, I'm little disappointed to see no replies.... :( any pointer will be very helpful.

I was also thinking of storing each of the of the key frames into a array and then reversing it and storing in the next cells of the array to imitate it, but it is a process heavy solution for a simple reverse and a simple send animate command to the parent and all children will animate kind of a solution :)

Link to post
Share on other sites

Well, at least it's an example of how to do it the way you were thinking.  It kind of makes sense that if the 'from' is lower than 'to' that BJS could use that to play the animation backwards.  I was just showing you my search, since you mentioned you had searched - I think it helps if 'babylonjs' is an early search term.

Link to post
Share on other sites

Hi @Sac

reversing the keyFrames and a negative speed value should achieve this.


scene.beginAnimation(rabbit, 100, 0, true, -0.4);

Edit; something is a bit weird, only seems to work if looping.

Edit_2; reverse animation without loop is now working thanks to @Adam; http://www.babylonjs-playground.com/#1LNWLE#12

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...