Zerod
Zerod

Reputation: 1

Collision handling with Rotated Rectangles

I am about to develop a little 2D game. The perspective is top Down like, so you can only see the Had of the player. You can move the Player with WASD and he and his Collision Box Rotates, in the Center of the Player, to the mouse Position. In the World are some rotated Walls, by which the Player can collide with.

I have a function for the Collision detection with 2 rotated Rectangles, but i don't know how to handle it.

Has someone a function, with takes the 2 rotated Collision boxes and gives me the right position back. Or has someone an example for such a problem?

Upvotes: 0

Views: 801

Answers (1)

Gareth Rees
Gareth Rees

Reputation: 65854

The algorithm you want is called the separating axis (or axes) test (this should help you search for it). The paper "Intersection of Convex Objects: The Method of Separating Axes" by David Eberly has a good description. Or see this answer of mine for a short summary.

Upvotes: 0

Related Questions