**download**

Host A

here is the collision code.

**end step event of obj_ball**

var vaP1,vaP2,dis,va1,vb1,va2,vb2,vp1,vp2,dx,dy,dt; with obj_ball { if id!=other.id { dx=other.x-x; dy=other.y-y; dis=sqrt(sqr(dx)+sqr(dy)); if dis<=radius+other.radius { //normalize dx/=dis; dy/=dis; //calculate the component of velocity in the direction vp1=hspeed*dx+vspeed*dy; vp2=other.hspeed*dx+other.vspeed*dy; if (vp1-vp2)!=0 { dt=(radius+other.radius-dis)/(vp1-vp2); //move the balls back so they just touch x-=hspeed*dt; y-=vspeed*dt; other.x-=other.hspeed*dt; other.y-=other.vspeed*dt; //projection of the velocities in these axes va1=(hspeed*dx+vspeed*dy); vb1=(vspeed*dx-hspeed*dy); va2=(other.hspeed*dx+other.vspeed*dy); vb2=(other.vspeed*dx-other.hspeed*dy); //new velocities in these axes. take into account the mass of each ball. vaP1=(va1+bounce*(va2-va1))/(1+mass/other.mass); vaP2=(va2+other.bounce*(va1-va2))/(1+other.mass/mass); hspeed=vaP1*dx-vb1*dy; vspeed=vaP1*dy+vb1*dx; other.hspeed=vaP2*dx-vb2*dy; other.vspeed=vaP2*dy+vb2*dx; //we moved the balls back in time, so we need to move them forward x+=hspeed*dt; y+=vspeed*dt; other.x+=other.hspeed*dt; other.y+=other.vspeed*dt; } } } }

**Edited by slayer 64, 01 September 2009 - 04:10 PM.**