Repeating value is incorrect over time
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 10.1k
- Forks
- 1.4k
- PR merge metrics
- No merged PRs in 30d
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No repository file or test is identified. Start with the TWEEN.Tween repeat/yoyo behavior and the React Three Fiber useFrame entry point, then reproduce overlapping calls with the 0-to-0.8 example; done means establishing whether the accumulated 0.00003 result is a library bug or an interaction between concurrent tweens.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100