I'm developing a game and I've found (a problem) and, to solve it, I need to return the intersection position and size.
Here's the rectangle collision detection code:
for (var i = 0; i < rects.length; i++) {
for (var others = 0; others < rects.length; others++) {
if (others != i) {
if (rects[others].y + rects[others].height >= rects[i].y &&
rects[others].x + rects[others].width >= rects[i].x &&
rects[others].x <= rects[i].x + rects[i].width &&
rects[others].y <= rects[i].y + rects[i].height) {
// They're intersecting!
intery = 0; // Intersection Y
interx = 0; // Intersection X
interw = 0; // Intersection Width
interh = 0; // Intersection Height
}
}
}
}