if player.x + player.width > platform.x and
player.x < platform.x + platform.width and
player.y + player.height > platform.y and
player.y < platform.y + platform.height then
-- Player and platform are overlapping
end
But my goal is to get the width and height of the resulting intersecting rectangle, and use that to properly resolve the collision.
For some reason I'm having a hard time trying to make sure I explain this properly, if its unclear please let me know
Now we can see, that if we want to get x of overlap, it is math.max(x1, x2) where x1 and x2 are x positions of two rectangles. Same applies to y. If we want to get x + w of overlap, it is math.min(x1 + width1, x2 + width2). Same applies to y. (basically, the left point of intersect is the rightmost left point, the right point is the leftmost of the right point, the top point is the lowest of top points and the lower point is the highest of lowest points).
Now we can see, that if we want to get x of overlap, it is math.max(x1, x2) where x1 and x2 are x positions of two rectangles. Same applies to y. If we want to get x + w of overlap, it is math.min(x1 + width1, x2 + width2). Same applies to y. (basically, the left point of intersect is the rightmost left point, the right point is the leftmost of the right point, the top point is the lowest of top points and the lower point is the highest of lowest points).
This is exactly what I was trying to solve thank you so much!
For anyone interested here's a simple little function for it