I have a problem with circle collision, not the collision detection itself but the handler that solves the collision.
To keep things simple I'll use two circles. One is has a radius of 50 and the other 30. When the circles are intersecting this is what the handler does
//Calculates distance between circles
var nDistX:Number = CircleB.x - CircleA.x;
var nDistY:Number = CircleB.y - CircleA.y;
var nDistance:Number = Math.sqrt ( nDistX * nDistX + nDistY * nDistY );
//Gets the radius
var radiusA:Number = CircleA.width/2;
var radiusB:Number = CircleB.width/2;
//Calculates midpoint
var midpointX:Number = ( CircleA.x + CircleB.x )/2;
var midpointY:Number = ( CircleB.y + CircleB.y )/2;
//Calculates the new position
CircleA.x = midpointX + radiusA * (CircleA.x - CircleB.x) / nDistance;
CircleA.y = midpointY + radiusA * (CircleA.y - CircleB.y) / nDistance;
MCBallB.x = midpointX + radiusB * (CircleB.x - CircleA.x) / nDistance;
MCBallB.y = midpointY + radiusB * (CircleB.y - CircleA.y) / nDistance;
The code above works flawlessly when concerning two circles with the same radius. When the circles intersect (spawning in coordinates close to each are for example) the circles move apart from each other.
The problem starts when the circles are of two different sizes. What happens when they intersect is what it looks like to be the the larger circle running away from the smaller circle while still attached.
Do any of you have an idea why this is happening?