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 a 3d moving box and a stationary box. I can detect collisions ok but now I would like to slide the moving box against the stationary box as a collision response. For this I need the normal of the face that collides with the moving box. Does anyone know how I figure this out? It doesn't seem like the collision test gives me this information. Any help is appreciated.

share|improve this question
The collision normal and the normal of the colliding face are different things. The collision normal depends on the subtracted velocities of the colliding objects. Whereas calculating the normal of a face is shown in Valkea's answer. For a proper collision response you will need both. –  Maik Semder May 30 '11 at 10:04

1 Answer 1

up vote 1 down vote accepted

In order to calculate the normal to a plane (the collided AABB face) you need:

  • 3 points of this plane (2 non parallel edges).
  • The cross product of two edge vectors of this plane (usually from the same point of origin).

This will produce a vector perpendicular to this plane (but a plane have 2 sides).

Here is an example of how to calculate the cross product.

Let A, B, C and D be the four points of your AABB collided side.

 |     |

If we use ABC, then the normal to the plane is

ADxAB (if we want a normal pointing out of the screen)
ABxAD (if we want a normal pointing inside the screen)

(it's just because our example is facing the screen, if the plane is seen from left side, the fist normal will point right and the second will point left)

As you can see the order in which you take the points will impact the side the normal will point to. That's why developers usually store their points in a specified order (clockwise or counter-clockwise, but the same for all faces) so they know in which order to use them.

See this on more details now:

AB = [ Bx-Ax, By-Ay, Bz-Az ]
AD = [ Dx-Ax, Dy-Ay, Dz-Az ]

Here is how to get the first normal

ADxAB = [ ADx, ADy, ADz ] X  [ ABx, ABy, ABz ]
      = [ (ADy*ABz - ADz*ABy), (ADz*ABx - ADx*ABz), (ADx*ABy - ADy*ABx) ]

And here come the second normal pointing to the other side

ABxAD = [ ABx, ABy, ABz ] X  [ ADx, ADy, ADz ]
      = [ (ABy*ADz - ABz*ADy), (ABz*ADx - ABx*ADz), (ABx*ADy - ABy*ADx) ]

If you replace the ABx, ABy, ABz etc. values with the differences calculated just before (Bx-Ax, By-Ay, Bz-Az etc.) the cross products you will get the normal vectors.

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.