Need help with ball bouncing around on the screen.

BlitzMax Forums/BlitzMax Programming/Need help with ball bouncing around on the screen.

JoJo(Posted 2008) [#1]
I'm trying to create a simple program where balls will bounce around on the screen.

The thing is sometimes the balls ricochet as they should and in the correct direction; and then sometimes they don't.

Sometimes balls go through each other.
They sometimes get stuck going in the same direction, and sometimes when two balls collide; one of the two balls would go in the opposite direction as it should, while the other one continues in the same direction as if it had never been touch.

Can you please take a look at my code and see what I'm doing wrong?




Kurator(Posted 2008) [#2]
Try to change the orden in which you do the update:

1.) Calculate the new positions of the ball
2.) Check against a collision
3.) Draw the ball.

This is also not correct by 100%, because for a defenitely correct collision you have to calculate the correct position of the collision - because if you recognice a collision at point 2 - you can not assume that the collsion happened at the balls new position, it is more likely that it happened somwhere between the two points, debending on speed and size of your objects