# Need help with collision urgently

This topic is 3149 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

What is the easiest and quickest way to see on what side two sprites collide? I'm making a zelda style game. I can get the collision to be detected, but it's only true or false. I can't push the character away from the wall if I don't know on which side did the collision happen. I'm using bounding boxes at the moment and the collision detection sees if all the sides from box A are outside of box B and then returns true or false. With this setup I can get it to work on top and left or bottom and right, but I can't get it to work on both at the same time. I would appreciate if someone could tell me with code what is the best way to get over this problem. This is part of school project and I only have few days left. I don't have the time to make anything complex so if anyone could show me a simple way to do this, I would be really grateful. PS. I don't have too much experience with programming. PS2. I'm using c++ / SDL

##### Share on other sites
It looks like this is a continuation of your thread here. (Sorry, when I mentioned that the topic was more 'Math & Physics' oriented, I didn't mean to suggest cross-posting. I probably should have been more clear about that though.)

Anyway, the answers in my other thread still apply. Of the solutions I proposed, I think that computing the minimum translational vector for the two boxes would probably be the most reasonable here.

You should be able to find info on how to do this if you search the forum archives for 'aabb mtd', 'aabb minimum translational distance', or 'aabb sat'.

In short, you need to compute four values representing how far box A (or B) needs to be moved in each of the four cardinal directions in order to resolve the collision. Each of these values can be computed by simple subtraction - if you draw a picture or two, it should become clear what value needs to be subtracted from what value in each case to yield the correct result.

Once you have the four values, select the one with the smallest magnitude; this will tell you which direction to move (+/- cardinal x or y axis), and how far.

1. 1
2. 2
Rutin
22
3. 3
4. 4
khawk
14
5. 5

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633743
• Total Posts
3013643
×