simple collision detection

Posted by Rob on Game Development See other posts from Game Development or by Rob
Published on 2012-03-24T17:25:07Z Indexed on 2012/03/24 17:38 UTC
Read the original article Hit count: 294

Imagine 2 squares sitting side by side, both level with the ground: http://img19.imageshack.us/img19/8085/sqaures2.jpg

A simple way to detect if one is hitting the other is to compare the location of each side. They are touching if ALL of the following are NOT true:

The right square's left side is to the right of the left square's right side.
The right square's right side is to the left of the left square's left side.
The right square's bottom side is above the left square's top side.
The right square's top side is below the left square's bottom side.

If any of those are true, the squares are not touching. If all of those are false, the squares are touching.

But consider a case like this, where one square is at a 45 degree angle: http://img189.imageshack.us/img189/4236/squaresb.jpg

Is there an equally simple way to determine if those squares are touching?

© Game Development or respective owner

Related posts about collision-detection

Related posts about geometry