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

RE: [pygame] This is why your ball vibrates



The solution: :)
 
see my previous post for some code.
 the problem was twofold: check somehow, if the ball moves SOO slightly, it is to be considered dead.
 
BUT! there also was a major flaw in the way the ball bounced back up: the speed was assumed to INCREASE all the way, even AFTER the direction is flipped.
 
this causes the ball to raise higher as normal, and gather some extra speed while falling the extra height, then get ejected back up again. Hence: a nervously bouncing ball!
 
the solution is to calculate the moment of hitting the ground, calculate the speed at that moment, THEN turn the direction, and handle the rest, so, in the last part, the speed is not INcreased, but, as should be, DEcreased by gravity.
 
this reduces the bouncing to ZERO!
 
I then also choose to cut the moving if the ball bounces within 3 frames, but you could also calculate the amount of milliseconds it will take the ball to bounce again, and silence the ball if it is back that same frame.
 
you could also NOT declare a ball 'dead', and just keep calculating the minute chances, getting ever smaller each iteration, and waste all that cpu power :) the vibrating ball problem was in the gravity error in the second part after bouncing.
 
It does not vibrate any more if you fix that, look at my code to see a working example in my previous message :)


Share life as it happens with the new Windows Live. Share now!