I am programming a 2D game. When a ball is launched it should decelerate and eventually come to a stop. I have implemented the deceleration part but when the ball nearly stops it starts accelerating. I understand that I should implement some kind of condition for when it should stop (when velocity is 0), however all of my attempts have failed.
These are my variables:
v, v0 - velocity
acc - acceleration
dt - delta time
Here is a code sample of how the velocity gets updated on every game tick:
v.setX(v0.getX() + acc.getX()*dt); v.setY(v0.getY() + acc.getY()*dt);