How do I get my bouncing ball to actually stop?

November 14, 2026 4 answers
Asked by 5x+mapfold_604

My Python ball keeps making tiny bounces near the ground. I reduce its velocity on impact and set it to zero below a threshold, but it still won't settle. What should I change?

Answers

8m+brasshinge_307

Setting velocity to zero for one update isn't enough if the next update applies gravity again. Once the ball is resting on the platform, keep it at ground height with vertical velocity zero until something gives it an upward velocity.

Use the same contact height everywhere: platform.y_pos minus ball.radius, assuming platform.y_pos is the top of the platform. Your collision test uses radius minus 5, while the reset uses the full radius. That leaves a gap between the two positions, so the ball can fall again after being reset.

After moving the ball, check whether its bottom has reached or passed the platform while it's moving downward. Clamp its center to the contact height. If the impact speed is small, set velocity to zero and mark it as resting. Otherwise, reverse and reduce the velocity.

Velto-3c:

If the ball can be launched again, clear the resting state when you apply the upward velocity.

Reply to this answer
Farnel.8k

Give gravity and bounce their own values. Gravity accelerates the ball downward each update. A restitution coefficient controls how much vertical speed remains after an impact, so the bounce can use velocity = -velocity * restitution.

Pick a coefficient between zero and one for diminishing bounces. Zero means no bounce, while one preserves the impact speed in this simple collision model. You still need a cutoff and resting behavior for the last tiny bounces.

Reply to this answer
t518+gasket_7

Check the threshold against the impact speed, not just an arbitrary tiny number. With gravity adding 0.8 per update, a cutoff much smaller than that may never catch the small impacts your update loop produces. Try a cutoff in the same ballpark and adjust it for how the motion looks.

Reply to this answer
h204~ribboncase_7

Per-frame drag is another option if you want air resistance, but it does a different job from losing energy at the bounce. For a simple ball on a platform, reducing speed at impact and handling the resting state is the more direct fix.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions