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'm loading a simple 6 sided cube from a UV-mapped FBX model and I'm using a BoundingBox to test for collisions. Once I determine there's a collision, I want to use the normal vector of the collided surface to correct the movement of whatever collided with the cube. I suppose this is a two-part question:

1) How can I determine which face of the cube was collided with during a collision?

2) How can I get the normal vector of that surface?

share|improve this question
    
Are you using an Axis Aligned Bounding Box (AABB) or an Oriented Bounding Box (OBB)? –  Steve H Jun 22 '11 at 0:24
    
I'll be honest, I've never heard of either of them. If I were to make an educated guess based on the names, I'd say AABB. –  Corey Ogburn Jun 22 '11 at 0:43
    
Of course the cubes themselves are axis aligned... so would that mean the bounding box is oriented with respect to both the cube and the axes. –  Corey Ogburn Jun 22 '11 at 19:41

1 Answer 1

up vote 1 down vote accepted

The Xna.Framework.BoundingBox isn't designed to help provide that information, it simply is able to check for a collision of the cube as a unit.

Determining which side collided sounds simple but it can actually be complex. You might want to look into SAT (Separating axis therory/Test). The result of which axis and whether it is + or - the center of the cubeBox will help you deduce in which face the collision happened.

Another quick & dirty would be to create 6 boxes around your main box, then when a collision is registered with the main box, see which 'outsideBox' is also involved and calculate a normal based on that. This would have challenges though if penetration is deep. A version of this idea would be to make each face its own thin box so you always know which box (face) the collision is on. Again, deep penetration may challenge that.

Another idea would be to create a class which holds the bounding box and also creates Plane objects that coincide with the faces of the cube. Then you could use the built in Plane intersection tests to see which side the collision was coming from and use that plane's normal.

share|improve this answer

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.