Recently here at Wooden H Studio we have uncovered a way to create some simple Axis Aligned Bounding Box, or AABB for short, to plane resolution, so let’s get started with how we did it!

## Standard Variables

As a standard AABB’s have a couple variables that when added together create an AABB, these include a position, and minimum value, a maximum value, additionally we made a simple plane that consists of a position, and a normal vector. So, let’s assume we already know that the AABB and the Plane are colliding and now we need to figure out how to move the AABB back up to where it isn’t inside the plane.

## The Calculations

What we did is we started off by using the closest point to a line test. Originally, we didn’t have a line to use so we needed to make one. We used the normal value of our plane and added it to the plane's position to give us the endpoint for our line, this way the plane could be facing any direction and we will always have a valid line to start. From here you can find the closest point using the closest point on a line test. To do this test you need to subtract the lines end position by the lines starting position and normalize it, I’ll call this the "Start To End" vector. Then you take the point you are trying to find, in this case, it is the AABB’s position, and subtract it by the lines start position. Next, we want to find the dot product of both of these values and multiply it with the "Start To End" vector. Lastly, we need to add this new vector to the plane's position and that is how you find the closest point!

Next up we need to find the extents of the AABB, which is simply the AABB’s maximum value subtracted by its position and that will give us the extents of our cube. We can use the extents to get a radius in coherence with the plane. To get this radius we once again use the dot product with the planes normal vector and our extents.

So now that we essentially have the AABB’s position projected onto our line and we have the "radius" of our cube all that is left is to perform a distance check. We can use the distance formula to see how far our closest point on the line is from the plane's position. From here we need to find how much overlap occurs between the plane and the AABB, well we have the distance the object is from the plane, and we have the "radius" of the cube, and we know the object is already colliding, so we can take the radius and subtract the distance from it to get the overlap. Now you can multiply this overlap by the planes normal and that will give you the force needed to keep it above the plane and not colliding with it, and that is how we have done AABB to Plane Resolution.

By Gage Dietz

## Discussion (0)