   Avoiding jitter at rest with impulse physics
  I've got some code to bounce balls around using impulse physics and it looks and behaves well. The problem is most noticeable when the balls start to stack up and gravity is dragging everything down. Everything wants to sink into the floor and when balls go out of bounds the position is reset back so it's not out of bounds and the velocity is reversed. It seems when the position is reset it causes an overlap which when resolved ends up pushing the ball back out of bounds again. I've tried a few workarounds but I'm sure there's a nicer solution which I haven't found written down yet. Can anyone offer any pseudo code to help or point me in the right direction to something to read? This is what I have so far.for all balls{  update position  for all the following balls  {    if the two balls are in collision then separate and resolve vectors  }  if the ball is out of bounds correct and reverse velocity  update friction and gravity}Here's a link to the exe, just click start and let it run to see what I mean.http://www.mediafire.com/?zzytmdytm52Cheers,Terry   
  If you update velocities (including collisions/contacts) _before_ updating positions then you can make object penetration the exception rather than the rule. ;  I've tried changing the order that the position is updated to no avail.I've also tried sorting the balls by the y position so balls on the ground are processed first. Added more velocity dampening. And reduced gravity to a tiny amount (per ball) when there's a collision. The latter showed a small improvement but still falls over when there's alot of stacking going on.   ;  When you iterate over all your balls and resolve collisions, do that loop some fixed number of times (like 10).  It's not a perfect solution but it will be less unstable.If you want the correct solution it becomes more involved and you have to dig in to matrix math.  Or you can just iterate over your resolving collisions loop until no balls are colliding more than some threshold, which amounts to basically the same thing.   