Skip to content

Repeating value is incorrect over time #660

@OldManMeta

Description

@OldManMeta

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy