Bouncing Ball

fork
Posts: 14
Joined: Wed Aug 03, 2005 3:47 pm

Bouncing Ball

Post by fork »

How do you guys get a bouncing ball to eventually come to rest? It would be nice if somehow the velocity and position became zero eventually due to floating point round-off errors.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

Most physics engines have several parameters so the velocity of a bouncing ball becomes zero after a while.

- Restitution coefficient: less then 100% restitution will bring back the linear velocity after every collision.
- velocity damping will generally reduce velocity every timestep
fork
Posts: 14
Joined: Wed Aug 03, 2005 3:47 pm

Post by fork »

Could you be more concrete on how that will stop all jittering?
jebus
Posts: 1
Joined: Thu Oct 19, 2006 2:36 am
Location: Western Australia

Post by jebus »

How much jittering are we talking about?
With any physics simulations, objects resting on other objects are generally always jittering to some degree which is also true in reality.
If you want to be able to make sure that an object remains absolutely still, then you could put in a check:

Code: Select all

if (vel.length() < minVel)
  vel = 0;
This way the ball's velocity will be considered zero when it is very small.
User avatar
SteveBaker
Posts: 127
Joined: Sun Aug 13, 2006 4:41 pm
Location: Cedar Hill, Texas

Post by SteveBaker »

Even if you didn't clamp it, the fact that the computer doesn't have infinite precision should mean that roundoff error will eventually allow the velocity to reach zero.

But since that could take quite a while and there are performance optimisations to be had by stopping things from moving unnecessarily, it's probably a good idea to clamp it anyway.