Collision Handleing System

I'm moving forward with a 3D game I've been working on, and I want to make a system of handling collisions which will allow me to handle many types of potential collisions. So what types of ways do people usually deal with this?

I'm just thinking about how to organize this type of thing, and make it work in a very customizable yet generic way.
Last edited on
The simple way of doing this would be to use a physics engine such as Bullet so that you can check for collisions easily. You can also write your own code that checks every single possible collision if you don't have many collision boxes.

The efficient way, but much more challenging way, would be to write some sort of binary space partitioning system such as a KD-tree. This could be used to easily sort through your objects to determine the nearest objects to the player. I'm not sure of this, but I believe that Bullet physics uses something similar so that it is very optimized.
I've basically got the detection down. What I'm brainstorming about now, is mostly how to handle the interactions between collidable objects in a fairly generic way.

For example, objects could each have general effects that they will impart on any object they hit. And then when a collision happens, it doesn't matter necessarily what the objects are.

And then in the Scene class, I have a unhanded collision vector which when a collision takes place, a collision object is added to it. Then I can iterate over the collisions,

Something like this,

1
2
3
4
for (auto &c : collisions ) {
    c.obj1.react( c.obj2.action( c.obj1 ) );
    c.obj2.react( c.obj1.action( c.obj2 ) );
}


Then I guess I will have a set of action types; objects may send an action of a certain type to be reacted to, and the reacting object either has a special reaction hard coded for this specific action type, or it could just no nothing about it and ignore it.
Last edited on

For example, objects could each have general effects that they will impart on any object they hit.

Meaning?

And then in the Scene class, I have a unhanded collision vector which when a collision takes place, a collision object is added to it. Then I can iterate over the collisions,

Why not do at the same time?
Topic archived. No new replies allowed.