target / current

This interpolation do not requires any timer. It is similar to a constant deceleration. The idea is to gradually reduce the difference between a target and a current value. The code is simplest:

float target = 0;
float current = 0;
...
target = 3;
...
// (in an animation for instance)
current += (target-current) * 0.1;

At each loop, the 10% of the difference is added to current. To avoid an infinite process, the addition can be controlled by 2 tests, one to apply the operation, and another to stop it if the difference is too small ( 0.0000001 in this case ).

if ( current != target ) {
    current += (target-current) * 0.1;
    if ( abs( target-current ) < 1e-7 ) {
        current = target;
    }
}

speed / current

This interpolation do not requires any timer either. It is similar to a bounce[1] interpolation. The idea here is to modify the speed of the current in order to reach a given value. Once accelerated, the current value might go further than the requested value. The speed is then adapted to go in the other direction, until the requested value is reached. Code is a bit less obvious than the target / current:

float target = 0;
float speed = 0;
float current = 0;
...
target = 3;
...
// (in an animation for instance)
speed = ( (target - current) - speed_roll ) * 0.35;
current += (target-current) * 0.1;


  1. Realistic Bounce and Overshoot, http://www.motionscript.com/articles/bounce-and-overshoot.html

online identity ∋ [ social ∋ [mastodon♥, twitter®, facebook®, diaspora, linkedin®] ∥ repos ∋ [github®, gitlab♥, bitbucket®, sourceforge] ∥ media ∋ [itch.io®, vimeo®, peertube♥, twitch.tv®, tumblr®] ∥ communities ∋ [godotengine♥, openprocessing, stackoverflow, threejs]]