# Actionscript 3 collision detection, stopping objects from going through eachother

**URL:** <https://forum.kirupa.com/t/actionscript-3-collision-detection-stopping-objects-from-going-through-eachother/318314>\
**Category:** flash\
**Created:** [January 16, 2011, 7:09pm UTC](https://forum.kirupa.com/t/actionscript-3-collision-detection-stopping-objects-from-going-through-eachother/318314 "2011-01-16T19:09:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![RapsFan](https://avatars.discourse-cdn.com/v4/letter/r/958977/32.png) [@RapsFan](https://forum.kirupa.com/u/RapsFan)\
**Post date:** [January 16, 2011, 7:09pm UTC](https://forum.kirupa.com/t/actionscript-3-collision-detection-stopping-objects-from-going-through-eachother/318314/1 "2011-01-16T19:09:38Z")

</div>

Hello everyone. 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

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”);  
}  
}
