Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

To allow my objects to slide when they collide, I need to :

  • Know which face of the AABB they collide with.
  • Calculate the normal to that face.
  • Return the normal and calculate the impulse that to apply to the player's velocity.


How can I calculate which face of the AABB I collided with, knowing that I have two AABB's colliding? One is the player and the other is a world object.

Here's what that looks like (problem collision circled in white):

problem collision

Thank you for your help.

share|improve this question
up vote 2 down vote accepted

Check each individual plane of the AABB against the other AABB. If a plane intersects the other object's AABB, but its opposing plane does not, you know that that plane is involved in the collision. If both opposing faces intersect the other AABB, then the object is fully within the other along that axis, and the direction of collision is ambiguous/undefined.

Practically speaking, these are the same checks used to determine if AABBs collide, so you should be able to determine which faces collide as you do the AABB collision check with little additional cost.

Looking at the example, we see that:

  • The sphere's yz+ plane intersects the prism, but yz- does not. Sphere yz+ collides. In a similar manner, the prism's yz- collides.
  • Both the prism xy- and xy+ are within the sphere's xy- and xy+. The prism is fully within the sphere in the z direction; collision is ambiguous.
  • Both the prism xz- and xz+ are within the sphere's xz- and xy+. The prism is fully within the sphere in the y direction; collision is ambiguous.

So, in this example, we detect a collision between the sphere yz+ and the prism yz-.

The normals of all faces should be obvious (yz+ has (1,0,0), yz- has (-1,0,0), xz- has (0,-1,0) ...) In general, if a quad has the vertices (a, b, c, d) in counter-clockwise order, then your can compute the normal with (b-a).cross(c-b)

Note that this problem does present the possibility of multiple collisions: depending on positioning, you can have collisions in all three axes. I think this 'ambiguity' is pretty inherent, and how you resolve it is really up to you. You might just take the average of the individual normals. You could find the area of intersection in each plane, and then choose the normal which corresponds to the largest area, or use the areas to weight the average of normals. You could find the intrusion depth along each axis, and pick the normal corresponding to the shallowest (or deepest) intrusion. Etc, etc.

share|improve this answer
Couldn't that be easier? Thanks ipeet - another long days,weeks for me to try to code it .. – PeeS Mar 22 '12 at 13:17
@PeeS - I feel like this is probably something that has been done many times. Perhaps you should look around for how other people have implemented it. – Richard Marskell - Drackir Mar 22 '12 at 15:43

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.