Game Development Community

Quick Question, Easiest way to check collision?

by Michael Bacon · in Torque Game Engine · 11/13/2007 (6:58 am) · 2 replies

I have a box, a start point and an end point. What is the easiest way that I can check to see if this box collides with anything in the world?

Thanks!

#1
11/18/2007 (4:57 pm)
If the box is always aligned with the start->end line, then just cast a ray from each of the 4 front corners parallel to the start->end line. Maybe also cast a ray down the line itself. This will generally tell you if there's anything that will stop the box, though it could miss very small objects because of the spaces between the rays. If the box is very large, and small objects could be between those rays, just cast more rays from other points within the corners.

To cast a ray parallel to the line, you'll just be doing a cast from (startPos+cornerOffset) to (startPos+cornerOffset+lineVector), where lineVector is the vector describing the path from start to end (literally endPos - startPos) and cornerOffset is the vector from startPos to the corner's position. Finally, an excuse to use some ASCII art!

___  _ _ _ _ _ _ castRay
|   |
|   | S---------->E
|___| _ _ _ _ _ _ castRay

If the box isn't aligned with the line, you'll need to basically figure out what its max extents are on the plane perpendicular to the line. Repeat the first procedure, using those extents as the corners.
#2
11/19/2007 (3:54 am)
That solution won't work for colliding against small objects and allows penetration of points and corners which will not be acceptable for a camera.

I'm looking for the proper way to implement swept box collisions. I believe I need to use the BoxConvex class but I'm not sure how to start.