🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

How to make a basic 3D collision detection system?

Started by
5 comments, last by Mussi 3 years, 12 months ago

Hi! I hope you're having a great day : )

I currently working on my first serious 3D game engine using C++ and OpenGL, yeah, I know, I should use a premade one but I'm crazy ; )

I've finished the very first part of the engine (which is some 3D shapes with basic transform), now, I want to start implementing a basic 3D collision detection system just so I can make playable content with this engine, I do plan on upgrading it in the future. But now I would love some suggestions about how can I even start creating it. I want something really basic right now, I just want to make shapes unable to go through each other, the more advanced things will come later.

So if you know about some sort of tutorial of how to make such a thing please tell me.

Thanks anyway!

Advertisement

The simplest you can do is box collision. Calculate an OOBB (object oriented bounding box) for your 3D meshes, those are the collider volumes you later use to test and finally implement a simple iterator based testing algorythm that calculates if the volumes overlap.

You can advance the algorythm by also adding a spatial positioning tree to test only objects against each other that are in certain area buth thats it.

If you want even more advanced and future proof stuff, you should take a look at general game physics and maybe some open source physics engine like Box3D

Much better primitive for soon rejection is AABS- axis aligned bounding sphere. The testing algorithm is more trivial, plus, it can be spatial and hierachical as well. As for implementing basic physics, you should do plane/triangle ray collision algorithm, all else basicly derives from that logic.

Hi, thanks for replying! :D

So should I start implementing AABB collision detection in my engine? I mean, I kinda need a way to make a box collision detection too. So should I go with AABB and create box colliders out of it or should I go straight for OOBB? I want to make slopes possible too.

btw, do you have any good tutorials for your techniques?

Thanks again!

OOBB is the better option because AABB stops working at the point where rotation turns in action. In an AABB scenario, your host model/ sprite/ whatever will blow up it's bounding box as it is axis aligned ans so always covers X/Y/(Z) vectors. OOBB might be a bit more difficult in how intersections are calculated (I did it with just a bunch of line-to-line intersection tests in a 3D driving game to determine if off-screen AI cars are colliding) but they're more future proof unless you plan to only create some Super Mario clon games with your code.

I don't have a tutorial for you but you should google for it and read for example an explenation of the theory on StackExchange

I can't recommend Christer Ericson's book Real-Time Collision Detection enough, it basically has all the answers and comes with code samples. It really is a must have.

This topic is closed to new replies.

Advertisement