2
\$\begingroup\$

I am having an extremely hard time understanding smooth 3D collision. I have spent a month trying to figure out the math and still cannot get perfect collision detection that perform the same way as in games such as Quake.

I've resorted to a virtual 2D rectangle collision model applied to 3D plane, but it's full of bugs and doesn't handle slopes. It seems that very complex math is required like matrices and vectors. There are lots of tutorials online but they are full of mathematical symbols and it's impossible for a math novice like me to understand it, I also don't have time to go through a mathematics basics from the beginning. Is it possible to do collision without vectors or matrices or a guide somewhere that can explain in non mathematical terms how to implement smooth collision? How can a nonmathematician overcome 3D math?

\$\endgroup\$
  • 6
    \$\begingroup\$ I'd say the best way for a non-mathematician to get good 3D collision behaviour is to use an existing engine which already provides this. Those vectors and matrices aren't just sprinkled in for fun - complex math is integral (pardon the pun) to accurate physics. But there's no need to reinvent the wheel yourself if you just want good gameplay - engines like Unity & Unreal give you everything you need without any up-front cost. Unless you're coding your own collision explicitly for the sake of learning; in which case, learning the math is a key step in your journey. \$\endgroup\$ – DMGregory May 19 '15 at 16:15
  • \$\begingroup\$ FYI generalized collision detection - for arbitrary shapes like what is needed for a physics engine - is achieved through algorithms like minkowski portal refinement (MPR) and GJK. Those algorithms make it so you don't have to write n^2 tests eg sphere vs sphere, box vs sphere, box vs box, triangle vs sphere, triangle vs box, triangle vs triangle. \$\endgroup\$ – Alan Wolfe May 26 '15 at 17:08
  • \$\begingroup\$ You seem to say that you don't have time: I also don't have time to go through a mathematics basics from the beginning. Then use a physics engine. People has been tackling this problem for decades and you don't have to start from the beginning. If you need to meet some deadline for a video game, this is what you should do. Otherwise, study math. I know it is not a simple topic and it is hard to find good, free, state of the art, entry level, tutorials that walk you from start to end... but it is worth it if you are into it. If you aren't, again, use a physics engine. \$\endgroup\$ – Theraot May 21 '17 at 13:05
3
\$\begingroup\$

If you want to calculate collision really fast, and without very complex math, use bounding spheres or cubes.

If you have a bounding sphere for each of the two objects, you would like to detect collision, it's really simple:

Sum the radius of the two sphere, and if it's less than the distance of the two objects, then are collided, else not.


Even the game engines don't calculate the collision for each triangle, they generate collision objects, which are simpler than the original ones

\$\endgroup\$
2
\$\begingroup\$

Vector math are really essential to detect proper collisions and the information to resolve it the properly. But its not that hard really:

Just 4 things you need to know about vectors to get started:

  1. Its just basic addition, subtraction, multiplication with the concept of doing it on "multiple" components at once (X, Y, Z in 3D and X, Y in 2D) - but each separatly and independently.

  2. Knowing that vectors are just a direction including a magnitude from a specific origin is the key to understanding it properly. Visualizing helps to understand it much better!

  3. The dot product is the key to solve most of the problems you encounter. Dot products are most of the time used as vector projections.

  4. Unit vectors just represents a direction the vectors points to. Every unit vector must have a magnitude of one.

\$\endgroup\$
0
\$\begingroup\$

Sphere collision is definitely the easiest to implement. Simply do distance checks between 2 objects. I.e.:

if ((ObjectA.Position - ObjectB.Position).magnitude > ObjectA.Radius + ObjectB.Radius)
{
    //Collision
}

For walls, you can use axis-aligned bounding boxes. For a sphere object, its bounding box min/max is its position added or subtracted its radius.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.