# Ping pong animation continuously

**URL:** <https://forum.babylonjs.com/t/ping-pong-animation-continuously/17178>\
**Category:** Questions\
**Tags:** animation\
**Created:** [January 5, 2021, 6:49am UTC](https://forum.babylonjs.com/t/ping-pong-animation-continuously/17178 "2021-01-05T06:49:24Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![M\_K](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/m_k/32/13269_2.png) [@M\_K](https://forum.babylonjs.com/u/M_K)\
**Post date:** [January 5, 2021, 6:49am UTC](https://forum.babylonjs.com/t/ping-pong-animation-continuously/17178/1 "2021-01-05T06:49:25Z")

</div>

I am using a GLTF model animation.I have written a code to ping-pong the animation using onAnimationEnd event and reversing keyFrames and negating the speedRatio. It works fine once but doesn’t loop.i.e. onAnimationEnd is called only once when animation goes from 0 to 9, not when it goes again from 9 to 0.  
What could possibly be wrong?  
Also one question not related to this : animation.animatables[0].masterFrame works only once when the animation hasn’t completed. Can anyone please explain animatables masterFrame. I just want to know the current frame always.

Playground : [https://playground.babylonjs.com/#49U34A#10](https://playground.babylonjs.com/#49U34A#10)

I am very new to Babylon. Any input would help. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [January 5, 2021, 9:32am UTC](https://forum.babylonjs.com/t/ping-pong-animation-continuously/17178/2 "2021-01-05T09:32:08Z")

</div>

Pinging @Drigax who may help here.

---

<div class="post-metadata">

**Author:** ![M\_K](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/m_k/32/13269_2.png) [@M\_K](https://forum.babylonjs.com/u/M_K)\
**Post date:** [January 6, 2021, 7:51am UTC](https://forum.babylonjs.com/t/ping-pong-animation-continuously/17178/3 "2021-01-06T07:51:50Z")

</div>

Can anybody help?

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [January 6, 2021, 9:50am UTC](https://forum.babylonjs.com/t/ping-pong-animation-continuously/17178/4 "2021-01-06T09:50:48Z")

</div>

I think @Drigax is still in vacation today, he will have a look whenever possible.

---

<div class="post-metadata">

**Author:** ![M\_K](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/m_k/32/13269_2.png) [@M\_K](https://forum.babylonjs.com/u/M_K)\
**Post date:** [January 7, 2021, 4:40am UTC](https://forum.babylonjs.com/t/ping-pong-animation-continuously/17178/5 "2021-01-07T04:40:55Z")

</div>

Ok…Thanks

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [January 8, 2021, 12:22am UTC](https://forum.babylonjs.com/t/ping-pong-animation-continuously/17178/6 "2021-01-08T00:22:34Z")

</div>

This playground doesn’t work for me.

> babylon.js:16 BJS - [16:21:52]: Unable to import meshes from Animation/Bee.glb: Error status: 404 - Unable to load Animation/Bee.glb  
> e.\_ErrorEnabled @ babylon.js:16

---

<div class="post-metadata">

**Author:** ![M\_K](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/m_k/32/13269_2.png) [@M\_K](https://forum.babylonjs.com/u/M_K)\
**Post date:** [January 8, 2021, 5:52am UTC](https://forum.babylonjs.com/t/ping-pong-animation-continuously/17178/7 "2021-01-08T05:52:49Z")

</div>

@bghgary Updated the playground : [https://playground.babylonjs.com/#49U34A#22](https://playground.babylonjs.com/#49U34A#22)

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [January 8, 2021, 7:48pm UTC](https://forum.babylonjs.com/t/ping-pong-animation-continuously/17178/8 "2021-01-08T19:48:34Z")

</div>

This was harder than I expected, but here it is:  
[https://playground.babylonjs.com/#49U34A#27](https://playground.babylonjs.com/#49U34A#27)

---

<div class="post-metadata">

**Author:** ![M\_K](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/m_k/32/13269_2.png) [@M\_K](https://forum.babylonjs.com/u/M_K)\
**Post date:** [January 11, 2021, 5:44am UTC](https://forum.babylonjs.com/t/ping-pong-animation-continuously/17178/9 "2021-01-11T05:44:35Z")

</div>

That’s perfect…Thanks a lot @bghgary

---

<div class="post-metadata">

**Author:** ![hjlld](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/hjlld/32/978_2.png) [@hjlld](https://forum.babylonjs.com/u/hjlld)\
**Post date:** [September 9, 2024, 3:06am UTC](https://forum.babylonjs.com/t/ping-pong-animation-continuously/17178/10 "2024-09-09T03:06:00Z")

</div>

Is it possible to set every animations’ loop mode to YOYO inside this animation group?

```auto
        currentAnimation.animatables.forEach(a => a.getAnimations().forEach(b => b.animation.loopMode = 4))

```

or

```auto
        currentAnimation.targetedAnimations.forEach(a => a.animation.loopMode = 4);

```

I tried, it doesn’t work, but why?

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [September 9, 2024, 8:52am UTC](https://forum.babylonjs.com/t/ping-pong-animation-continuously/17178/11 "2024-09-09T08:52:06Z")

</div>

You must set the loop mode before the animation is started. You can do it like this:

> **[Babylon.js Playground](https://playground.babylonjs.com/#49U34A%2334)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL and WebGPU 3D scenes
