How to make the animation pause at a certain frame and then continue to play at a certain frame?

How to make the animation pause at a certain frame and then continue to play at a certain frame?

I think this can be done by:

Define pause frame:
const pauseFrame = 50;

Start animation:
let animatable = scene.beginAnimation(target, from, to);

Pause animation:
if (animatable.getAnimations()[0].currentFrame === pauseFrame) animatable.pause();
The if condition above needs to be checked every frame of the animation. I’m not sure inside which loop to check this if condition. I wonder if inside scene.onAfterAnimationsObservable.add(() => { // if check here }) could work?

Continue animation:
animatable = scene.beginAnimation(target, from, to);

Reset and restart animation:
animatable.reset();
animatable.restart();

3 Likes

A useful playground (PG) https://www.babylonjs-playground.com/#0HJQEB#3 to get you started

3 Likes

thanks so much ~~~ @gbz @JohnK

3 Likes