AnimationGroup - TargetedAnimation - get current animation frame?

Hi guys. I understand that this question has been asked in the past, but unfortunately previous answers didn’t help me.

Here is a playground explaining the issue.

Basically, I’ve created like hover animation.

  1. user hover over the object, it animates.
  2. user hover out the object, it animates back

If user hovers out before the initial hovering over animation is done, I want to get the current frame of the animation where it stopped and start hoverOut animation from that frame to starting frame (0).

Currently, if you hover out while hover over is playing, it will play the hover out animation from end to begining (animation.to, animation.from).

So basically instead of having
hoverAnimation.start(false, 2, hoverAnimation.to, hoverAnimation.from);

It should be something like
hoverAnimation.start(false, 2, currentFrame, hoverAnimation.from);

I saw people mentioning
hoverAnimation.animatables[0].masterFrame

But hoverAnimation.animatables is empty object in my case (if you remove comments on console logs in the code you can see that).

How can I deal with this properly? I don’t want my animation to “jump” if I leave the hover early.

AnimationGroup.animatables[0]?.masterFrame might not be available if the animation is not started yet or if it is pause. You can add an additional check and assign it to default values if it is not preset.

I have modified you playground with a code that makes it work:

Babylon.js Playground (babylonjs-playground.com)

3 Likes

Amazing. Thank you so much, solved it. :slight_smile: