Tween.js how to do a yoyo animation

Hi,

Sorry first for this stupid question but really i don’t sucess to make a simple tween with yoyo on my cube. (i come from Phaser and tween is just a formality)

i have follow the RTFM but i don’t sucess…

Could you tell me where i’m wrong ?

Thanks

Use the tween lib included with threejs

https://jsfiddle.net/26tgaufc/13/

demo1

4 Likes

Hi,

Thanks for your jsfiddle. In fact the libs used in your snippet is the same that i would use : tween.js.

I miss tween.update() in animate (on phaser it’s not necessary) and i success with yoyo.

Thanks

2 Likes

This is a recurrent question. Most of the time, it’s because we don’t set a repetition.

tween.repeat(0) // 1 normal

Tween.yoyo needs some repetition to happen:

tween.repeat(1) // 1 normal, 1 reverse
tween.repeat(2) // 1 normal, 1 reverse, 1 normal
tween.repeat(3) // 1 normal, 1 reverse, 1 normal, 1 reverse
tween.repeat(-1) // infinity

Sometimes I fall into this question too :smile:

1 Like