# Critique my theoretical procedure for swept box collision

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

## Recommended Posts

I've never written my own swept collision procedure before and want to make sure I've got things down, first. So, tell me if, what and how this works/doesn't work.

Pseudo-code for a swept BoxBox collision check:
 Box boxOnePos0 in boxOnePos0's reference frame Box boxOnePos1 in boxOnePos0's reference frame Box boxTwo Rotate boxTwo into WorldFrame Transform boxTwo into in boxOnePos0's reference frame Rightmost edge of boxOnePos0 form face with Rightmost edge of boxTwoPos1 Leftmost edge of boxOnePos0 form face with Leftmost edge of boxTwoPos1 Topmost edge of boxOnePos0 form face with Topmost edge of boxTwoPos1 Bottommost edge of boxOnePos0 form face with Bottommost edge of boxTwoPos1 Result is boxOneSwept for faceOne in boxOneSwept axis is faceOne normal for faceTwo in boxTwoSwept projectTwo is faceTwo along axis distanceTwo is distance between faceOne.Middle and faceTwo.Middle if distanceTwo minus projectTwo is greater than zero, then return NoCollision next next return Collision 

So, critique, comments, improvements, suggestions?

Thanks.

##### Share on other sites
Hi,

I assume you're doing OBB vs OBB not AABB vs AABB?

Have you written static OBB vs OBB before? I'm pretty sure you're missing a bunch of edge vs edge cases in there.... Swept OBB vs OBB is basically just ray-cast against the Minkowski Difference of both OBBs. The MD in 3d is formed of vertex vs face, face vs vertex and edge vs edge feature pairs (or axis as in SAT)...

Cheers, Paul.

##### Share on other sites

Hi,

I assume you're doing OBB vs OBB not AABB vs AABB?

Have you written static OBB vs OBB before? I'm pretty sure you're missing a bunch of edge vs edge cases in there.... Swept OBB vs OBB is basically just ray-cast against the Minkowski Difference of both OBBs. The MD in 3d is formed of vertex vs face, face vs vertex and edge vs edge feature pairs (or axis as in SAT)...

Cheers, Paul.

Yes, OOB. Yes, I've written static OBB vs OBB before.

My basic idea was, if the extent of a face (from its midpoint) in the direction of the other face's normal is greater than the distance between their midpoints, then they're colliding. Thinking it over again, it isn't accurate in the case where one face goes past, but does not collide with, the other.

Revised to be less clever:
 Box boxOnePos0 in boxOnePos0's reference frame Box boxOnePos1 in boxOnePos0's reference frame Box boxTwo Rotate boxTwo into WorldFrame Transform boxTwo into in boxOnePos0's reference frame Rightmost edge of boxOnePos0 form face with Rightmost edge of boxTwoPos1 Leftmost edge of boxOnePos0 form face with Leftmost edge of boxTwoPos1 Topmost edge of boxOnePos0 form face with Topmost edge of boxTwoPos1 Bottommost edge of boxOnePos0 form face with Bottommost edge of boxTwoPos1 Result is boxOneSwept for faceOne in boxOneSwept for vertexTwo in boxTwoSwept projectTwo is vertexTwo in faceOne.ReferenceFrame distance is projectTwo.Z - faceOne.Z If distance is greater than zero, return NoCollision next next Likewise faceTwo, vertexOne for axisOne in boxOneSwept for axisTwo in boxTwoSwept referenceFrame is axisOne crossed with axisTwo projectOne is edgeOne length along referenceFrame // edgeOne is axisOne along referenceFrame projectTwo is edgeTwo length along referenceFrame // edgeTwo is axisTwo along referenceFrame distance is (distance between boxOneSwept.Center and boxTwoSwept.Center) length along referenceFrame if projectOne + projectTwo is less than distance, return NoCollision return Collision 

Thanks.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 9
• 11
• 15
• 21
• 26