Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
1  
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

3 Answers 3

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

http://www.gamasutra.com/view/feature/3383/simple_intersection_tests_for_games.php?page=3

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

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

Here are a couple of random ones:

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.

http://www.codeproject.com/KB/GDI-plus/PolygonCollision.aspx

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

Your Answer

 
discard

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.