2
\$\begingroup\$

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.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – brandon
    Commented May 1, 2011 at 16:32
  • \$\begingroup\$ 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. \$\endgroup\$
    – yelnats
    Commented May 1, 2011 at 17:00
  • \$\begingroup\$ Is your player modelled with an AABB box? \$\endgroup\$
    – Ray Dey
    Commented May 1, 2011 at 20:59
  • \$\begingroup\$ Well the player never gets rotated but yeah they do have a bounding box. \$\endgroup\$
    – yelnats
    Commented May 1, 2011 at 21:01

3 Answers 3

2
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ That's my problem, finding out which face is colliding, as in the point of entry. \$\endgroup\$
    – yelnats
    Commented May 1, 2011 at 20:46
  • \$\begingroup\$ 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. \$\endgroup\$
    – yelnats
    Commented May 1, 2011 at 23:27
0
\$\begingroup\$

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

Here are a couple of random ones:

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .