dsgmLib
dsgmLib copied to clipboard
collision with 3d objects
hi, im trying to detect collision with 3d objects in dsgmlib. I'm using the Galaxy example with some code from the collision example. the code compiles fine, but when mario and the goomba collide, nothing happens. what i expect to happen is the word "collision" appears on the bottom screen, but it doesn't appear. what is the correct code for this to happen?
The collision functions are 2D. You will need different logic to detect collisions in 3D space.
Ok... so then what kind of logic do I need... like examples
@skompc It really depends on the type of your game and the accuracy of the collisions you wish to have.
For top-down shooter games, for example, you can use a circle to represent the player, squares for the walls and do regular 2D collision checking.
For 3D you would surround your objects with what is called a bounding volumes, a sphere or a cube, for example. Then you would iterate all of your object and check if those bounding volumes are intersecting which is pretty simple to do. Lots of algorithms online.
If you have too many objects, iteration will be very slow. This is why you should also implement a scene manager (Binary-Space Partioning Tree) which will split your scenes into sections. The objects in one section will not collide with objects from another section, so you can reduce the number of objects you need to check for collisions.
When two bounding volumes intersect, you can use a per-triangle collision check, i.e. check each triangle of one of the objects if it intersects with the triangle of the other.
Hope this helps. I did not include any articles as there is plenty of info online. I just gave you starting points.