How can I test if my rotated rectangle intersects a corner?
Posted
by
Raven Dreamer
on Game Development
See other posts from Game Development
or by Raven Dreamer
Published on 2012-11-30T04:44:18Z
Indexed on
2012/11/30
5:28 UTC
Read the original article
Hit count: 340
collision-detection
I have a square, tile-based collision map. To check if one of my (square) entities is colliding, I get the vertices of the 4 corners, and test those 4 points against my collision map. If none of those points are intersecting, I know I'm good to move to the new position.
I'd like to allow entities to rotate. I can still calculate the 4 corners of the square, but once you factor in rotation, those 4 corners alone don't seem to be enough information to determine if the entity is trying to move to a valid state.
For example:
In the picture below, black is unwalkable terrain, and red is the player's hitbox. The left scenario is allowed because the 4 corners of the red square are not in the black terrain.
The right scenario would also be (incorrectly) allowed, because the player, cleverly turned at a 45* angle, has its corners in valid spaces, even if it is (quite literally) cutting the corner.
How can I detect scenarios similar to the situation on the right?
© Game Development or respective owner