AABB overlap correction not working

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

Recommended Posts

I've been having a problem with correcting the positions of AABBs that have collided. I'm using SAT to detect collisions and that works. The problem is the position correction that should be applied to each AABB (before the forces are applied - the normal force works but gravity drags the AABBs through each other).
Before                       After
-----------                  -----------
|                            |
-----------                       |-----------
|  <-|                            ||
|->  |                            ||
-----------                       |-----------
|                            |
|                            |
-----------                  -----------

The position corrections in this case are the two vectors shown on the before side (which are just mirrors of each other). I was calculating this position correct based on SAT vector, the direction vector of the moving box (testing against a static immovable AABB and a moving AABB), and the overlap values from the SAT.
Vector3 SAT;
SAT = moving.center - static.center;
float y_overlap = SAT.y - ( moving.half_scalars.y + static.half_scalars.y );

// Use the SAT vector variable as the position correction
SAT.normalize();
SAT.y *= y_overlap; // Just testing the case of a falling AABB

// Project the SAT position correction onto the moving box's direction vector
Vector3 pos_correct;
pos_correct = project( moving.velocity.normalize(), SAT );

// Apply the position correction to the moving box (negate it because SAT vector
// points to the static box
moving.position -= pos_correct;

This code sets the moving box's position at a huge y value. Any suggestions? Questions? Articles?

Share on other sites
Ignore this topic - I found the bug. I was testing

Xval = ( box1.half_scalars.x + box2.half_scalars.x ) - | SeparatingVector.x | ;

This is what was causing the correction vector to be so large.

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
17
5. 5

• 14
• 30
• 13
• 11
• 11
• Forum Statistics

• Total Topics
631774
• Total Posts
3002295
×