The age-old question of circle collisions

Hello,

As my title implies, I am stuck with the very popular question, “How do I get 2 circles to bounce off eachother correctly??”. I am currently making an air hockey game and have been looking for an answer for this for a few months now. I have seen great physics explanations, and great swf’s, but I can’t seem to do it myself. I know how to get the puck to bounce off the walls, and that code is very stable/simple, but the hitter-against-puck collision is very elusive. Bit-101 has some great swf’s on flashkit forums about the exact same thing I am looking for. I have heard of somebody on super samurai giving a great explanation. I have seen a physics student’s explanation. It seems to be a lot of code involving the radii of the circles, and the only thing I really understand is this:

r1 = radius of puck | r2 = radius of hitter | d = distance between them

if r1+r2 > d, then they have collided.

I know, I know, what you’re saying is,“well duh”. If somebody could explain to me how to write this code (you don’t have to give the code) that would be great.

Here is my puck-against-wall code:

onClipEvent (load) {
speed = 0;
dist = 0;
dx = 1;
dy = 1;
}
onClipEvent (enterFrame) {

   xspeed = 5;
   yspeed = 5;
   
   if (_x<47.6) {
           _x = 47.6;
           
           dx *= -1;
           
   } else if (_x>562) {
           _x = 562;
           
           dx *= -1;
           
   }
   if (_y<82) {
           _y = 82;
           
           dy *= -1;
           
   }
   if (_y>318.1) {
           _y = 318.1;
           
           dy *= -1;
           
   }
   
   _x = _x-(xspeed*dx);
   _y = _y-(yspeed*dy);

}

So anyway, obviously that code is inside of the puck. Help please if you know how.

thank you!:hugegrin: