I have coordinates, and I need them to decrease smoothly with a slowdown in the end. For example: 40, 20, 10, 5, 2.5, 1.25, 1.125, 0.925 and so on to ~0 The launch is quick, and the end is smooth.
I tried to use setInterval, and multiply by 0.9 each millisecond. But when it stops number is still either too much higher than the required number or too missed.
var friction = 5,
frict = setInterval(function()
{
sprite.position.x -= friction;
if (sprite.position.x <= finishline.x)
{
friction *=0.9;
if (friction < 0.05)
{
clearInterval(frict);
}
}
},5);
I expect the number 50 to smoothly drop to 0 in a short time and a noticeable smooth deceleration at the end.