# How to stop a decelarating object?

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);

• How are you computing your acceleration? – DMGregory May 5 at 14:06
• @DMGregory acceleration = friction coefficient * g, acceleration is constant – lucyKel May 5 at 14:13
• If you want the object to stop and stay stopped, then acceleration cannot be constant. (A stationary object subjected to constant acceleration will begin to move) Acceleration due to friction should depend on the direction of the velocity vector too, so it will be non-constant in that regard too. – DMGregory May 5 at 15:06
• @lucyKel Welcome to GDSE. While this could probably be addressed in a language agnostic manner, you might also want to edit the question to include a tag for the language &/or framework you're using. – Pikalek May 5 at 15:09
• @DMGregory I have implemented acceleration as a vector that points in the opposite direction of the velocity. Do you mean the acceleration also has to be updated on every game tick? If so, the how? – lucyKel May 5 at 15:33