Question

In a program i have moving objects. Their velocyties are described with a Vector(x, y).
So, i want the Objects to slow down - if they get speed for example because of a collision i scale them down in the next frames (with the factor 0.999) until they stop, because the velocity is so small, you cannot see them moving (java gets to 1e-50 or sth like that).

Its working, but actually its not correct because scaling them down they will never stop in theory. So how can i let the velocity go to zero, and let it REACH zero?

Was it helpful?

Solution

Just set it to zero once it drops below some threshold:

if (velocity.magnitude() < threshold) {
    velocity = new Vector(0, 0);
}

This will, however, eventually happen on its own due to arithmetic underflow.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top