Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have recently run into some trouble with my collision detection. My game is composed of a map made out of axis aligned squares. The player has an x and y velocity, and I want to know how I can find out with which side the player is colliding. So if they move left, I want to know that if they collide with a square, and with which side they collide with it.

Edit: Basically, what I want to know is how to find out which face the player is colliding with.

share|improve this question
It's pretty important to know which physics engine you are using or if you are making your own. The latter would require a much more advanced answer. – brandon May 1 '11 at 16:32
It is the latter. I don't really have much of a physics engine, it's just has velocity. No friction or anything advanced. Velocity is set to 0 as soon as you stop pressing buttons as well, so it's not too hard. – yelnats May 1 '11 at 17:00
Is your player modelled with an AABB box? – Ray Dey May 1 '11 at 20:59
Well the player never gets rotated but yeah they do have a bounding box. – yelnats May 1 '11 at 21:01

The "right" way to do this is probably with swept collisions.

Was the result of 5 seconds of googling, but if you look for swept and AABB, you should be able to find a lot of resources.

share|improve this answer

If you're ok with using c# example code, here is an example of 2d polygon detection. It may get you started, there's a lot to put into a QA answer.

Otherwise, just google polygon detection. Once you know which ones are colliding, finding out on which face should be easy.

share|improve this answer
That's my problem, finding out which face is colliding, as in the point of entry. – yelnats May 1 '11 at 20:46
To further this question, everything is a square so just querying every block the player can be touching in it's bounding box is easy. The problem I am facing is seeing if it is a vertical collision or a horizontal collision. I don't want to do the whole move the x axis, then move the y axis first, because that leaves weird traces when moving both left and down. As in you would probably stop moving on a wall that you would normally overcome. – yelnats May 1 '11 at 23:27

There are solutions for this all over the internet, stackoverflow and gamedev.SE.

Here are a couple of random ones:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.