-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Hi,
I'm using the lib to attempt to increment a value from a start to a target, and then back down to the start again.
I am using the following code:
// Set up the TWEEN animation
const tween = new TWEEN.Tween({ value: startValue })
.to({ value: endValue }, duration)
.repeat(1) // Repeats the animation once (forward and backward)
.yoyo(true) // Causes the animation to play forward and then backward
.onUpdate(({ value }) => {
console.log('Updating tween',value);
})
.onComplete(({ value }) => {
console.log('Completed tween=>',value);
})
.start();
}
I'm calling an update withing a React Three Fiber useFrame() hook, which is executing at 60 FPS.
The issue occurs given that the method containing this code, could be called several times in a second, and indeed the same target value could be being modified at the same time if the duration of the up and back has not stopped.
It's only a small end value difference - so if the start value is 0 and the end value is 0.8, after a few instances of this, the return to the start value in the onComplete method, shows that the value is now 0.00003 instead of pure 0.
The error is then amplified on each successive call to the code.
This of course could be me just not understanding and making the mistake in my coding?
Many thanks