I'm running a HitTestPoint to detect when two of my mc's collide, but I don't want them to be able to go right through each other. Someone suggested I find the x,y coords of the moving object when the collision occurs, then update that mc's coords to this x,y each time a collision occurs. I've been Googling but came up empty. Below is my code and what I tried
private function __checkHit($evt:Event):void {
if (this.coin_mc.hitTestObject(target)) {
if (!hitting) {
coinSnd.play();
count++;
total_count.text = String("$" + count);
hitting = !hitting;
}
} else {
hitting = false;
}
if (mug_bounds.hitTestPoint(coin_mc.x,coin_mc.y, false))
{
// do our in-circle check
if((mug_bounds.x - coin_mc.x) * 2 + (mug_bounds.y - coin_mc.y) * 2 <= (mug_bounds.width/2 + coin_mc.width/2) * 2)
{
**var coinX:Number = coin_mc.x;
var coinY:Number = coin_mc.y;
trace(coin_mc.x);
trace(coin_mc.y);
coin_mc.x = coinX;
coin_mc.y=coinY;**
}
}
else
{
trace("Didn't Hit Mug");
}
}
}