rendered paste body for(i=0; i < _root.Balls.length; i++)
{
for(j=i+1; j < _root.Balls.length; j++)
{
var dx = _root.Balls[i]._x - _root.Balls[j]._x;
var dy = _root.Balls[i]._y - _root.Balls[j]._y;
if((dx*dx + dy*dy) < ((20+20) * (20+20))) // Hit
{
trace('hit' + i);
var hitangle = (Math.atan2(dx, dy)) / Math.PI * 180;
var s1 = Math.sqrt(_root.Balls[i].velocity[0] * _root.Balls[i].velocity[0] + _root.Balls[i].velocity[1] * _root.Balls[i].velocity[1]);
var s2 = Math.sqrt(_root.Balls[j].velocity[0] * _root.Balls[j].velocity[0] + _root.Balls[j].velocity[1] * _root.Balls[j].velocity[1]);
if(s1 > 0)
{
_root.Balls[i].velocity[0] /= s1;
_root.Balls[i].velocity[1] /= s1;
}
if(s2 > 0)
{
_root.Balls[j].velocity[0] /= s2;
_root.Balls[j].velocity[1] /= s2;
}
var len = Math.sqrt(dx*dx + dy*dy);
if (len > 0)
{
dx /= len;
dy /= len;
}
}
}
}