I need to block two rectangles colliding with each other in Action Script. The code I have works only dimentionally(only a X on X collision or a Y on Y). When I test if it's colliding on the X axis and the Y, they interfere.
function collisionTest(obj1, obj2) {
var b1 = getBound(obj1);
var b2 = getBound(obj2);
if(((b1.x < b2.x + b2.width) && (b1.x + b1.width > b2.x)) && ((b1.y + b1.height > b2.y) && (b1.y < b2.y + b2.height)))
{
if(b1.x + b1.width > b2.x + b2.width)
obj1.x = b2.x + b2.width;
else if(b1.x < b2.x)
obj1.x = b2.x - obj1.width;
else if(b1.y < b2.y)
obj1.y = b2.y - obj1.height;
else if(b1.y + b1.height > b2.y + b2.height)
obj1.y = b2.y + b2.height;
}
}
If there is any other way to test for a collision and block it, then please tell me, but I've searched on Google, and stackoverflow, and haven't found anything useful for blocking the collision, however I've found a lot about testing for them.