   Collision Detection?
  im creating a mini trick shot snooker game and have created all the objects i need and coded the movements of the balls and took friction into account, and now i've come to collision detection, i started with the easy part ie collision detection with the walls of the table - which is basically the edge of the screen.i am currently detecting collision in the update function of the balls, and is a very simple test of weather the balls position is less than or greater than the edges of the screen and if so change the angle it is moving at, though when i do this, it somtimes changes the angle many times at the edges of the screen until the ball moves away, is there any way to stop this happening?p.s the code im using for the aftermath of a collision isn't very good i think, basicaly if the ball hits the top or bottom of the screen then i negate the balls movement angle, and the sides i + or - 90 degrees from them - not good i know, is there a better way?   
  Your post asks two questions.On collision detection If you only run the collision detection algorithm once per update step, then your algorithm is inherently flawed and will miss collisions or give incorrect results. You can keep approximating and use multisampling (that is, when a collision is detected, move back the ball in time, divide the speed and the step duration by 10 (or an arbitrary constant) and perform movement/collision detection again ten times in a row to increase precision. You can also decide to do it cleanly the following way: compute the time of the collision with the wall. If it occurs within this frame (that is, the collision happens before the end of the frame duration), then move the ball by that time, perform collision response, and start over again (but with a shorter duration) until the end of the frame is reached.On collision responseWhen collision occurs, compute the tangential plane between the ball and the other object (in the case of walls, that plane is simply the wall). Then, if V is the velocity of the ball and N is the normal to the plane, you have the two following quantities prior to the collision:V.N (normal speed)V - V.N (tangential speed)Then, your post-collision velocity is:V' = a * V.N + b * (V - V.N)Where b is a friction coefficient (that slows the ball's tangential movement, based sometimes on the effect applied to the ball) and a is an amortizing coefficient (which reduces the bounce amplitude).   