As I’m sure most of you know, movieClips are squares, despite what’s inside them. I have two circle movieClips (one that is the character in my game, and one thats stationary).
I’ve been attempting to use the distance formula to dectect collision on the circles, however, it’s not working for whatever reason.
Here is my code (mc names are character and ball):
var r2:Number = character._width + ball._width;
var dx:Number = character._x - ball._x;
var dy:Number = character._y - ball._y;
var distSq:Number = dx * dx + dy * dy;
onEnterFrame = function(){
if(Key.isDown(Key.LEFT)){
character._x -=1;
}else if(Key.isDown(Key.RIGHT)){
character._x +=1;
}else if(Key.isDown(Key.UP)){
character._y -=1;
} if(Key.isDown(Key.DOWN)){
character._y +=1;
};
if(distSq < r2 * r2){
trace(“object hit”);
};
};
can someone either tell me why this is not working and/or a better way to test for collision in circles?