[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Why does my ball vibrate?



On Nov 28, 2007 3:38 PM, Kevin <kevinmccloud@xxxxxxxxx> wrote:
A somewhat simple fix to get the ball to stop bouncing would be like this (put after velocity is set to newvelocity):
if abs(velocity) < 0.01:
  gravity = 0
  velocity = 0
I'm not sure that would work.  At the top of a parabolic arc, Physics says that the ball's velocity is temporarily zero.  So if you're starting from rest, it won't fall at all.  If it starts with some velocity, it will stop at the maximum of the parabola.  A solution would be to have it also check for the ground level.  When I wrote Marble Madness, ( http://www.pygame.org/project/471/), for example, exploding particles hung disturbingly in the air until I checked for the ground level (mercifully simple, because it was flat). 

Incidentally, I noticed your parameter for gravity was 9.8.  As in 9.8m/s.  I'm probably stating the obvious, but I'm guessing you're using the framerate to calculate to motion because it's a simulation, which requires accurate time. 

Also, I suggest that you change the collision detection to: "
if ypos => 384 and velocity > 0:
    velocity = -velocity * bounce
" ("==" becomes "=>") so that you don't have the extra code.

Hope this helps,
Ian