• Advertisement
Sign in to follow this  

AABB overlap correction not working

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
Ignore this topic - I found the bug. I was testing

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

instead of what was posted.

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement