I have chained 4 different tweens
to create a loop, and one of the tweens
that i want to happen is when loaded gltf
model reaches certain y: position i want it to rotate for additional 90 degrees. But currently it just rotates from 0 to 90 degrees everytime it reaches that certain y: position.
...
var currentRotation = 0;
const tweenRotation = new TWEEN.Tween({ z: currentRotation })
.to({ z: currentRotation + MathUtils.degToRad(90) }, 2000) // 2s linear tween for rotating 90dg
.easing(TWEEN.Easing.Linear.None)
.onUpdate((rotationFunc) => {
model.rotation.z = rotationFunc.z;
currentRotation += MathUtils.degToRad(90);
})
.onComplete(() => {
currentRotation += MathUtils.degToRad(90);
});
...
I also tried storing the initial rotation value as a
var currentRotation = model.rotation.z;
but it did not work, however when i console.info inside .onUpdate
for current rotation it seems like its adding up value each time as expected but keeps teleporting the 0 degree to rotate for 90 degrees everytime. Any help would be appreciated!
I found the solution by delaying the start of chained 2nd tween after first tween gets finished. In that specific time window, rotation happens.
I also changed the way I wrote for the rotation, now it is in a function. I can now change the degree parameter and just execute the function to add certain degrees each lap as i want.