Collision detection in 3D

Started by
7 comments, last by Drki 24 years ago
I have just switched from 2D to 3D and I was wondering how do you do a collision detection. In my 2D game I used it like this (maybe it is stupid, I dont know?): 0000000**000 000000****00 00000******0 000000****00 0000000**000 When a character moves it reads a bit from matrix, if it is a ''0'' he can move and if it is ''*'' the colide hapend. In 2D it used a lot of memory, cant image what it would do in 3D, so now I need to do something difrent,but dont know what. How the collision works in Half-life, Quake ... Thanks
Advertisement
...
I''ll try to explain how it works.
First, you know every objects movement, direction...
For each moving objects, you check if it may encounter (any)another object within the time frame.(time detween the frame already drawn and the one to draw)

You can create boxes or spheres around the moving objects and check if it cross something.

Maybe checking using quatree or something will help.
(You need to optimise this)

The problem is that maybe between the two frames objects have pass through each other...
I don''t remember how to check that

Check Gamasutra they''ve articles about collision detection...

That''s all I can do for you, now.

-* Sounds, music and story makes the difference between good and great games *-
-* So many things to do, so little time to spend. *-
to be more precise :

http://www.gamasutra.com/features/index_va_programming.htm

it''s a link to many articles including some on collision detection in 3d space.

Hope it helps.

-* Sounds, music and story makes the difference between good and great games *-
-* So many things to do, so little time to spend. *-
So, what are you saying if I have 400 objects (walls,doors), I have to check all of them if they are colliding?

Thats a lots of IF-s,man.

Thanks,anywhay.


No, you don''t need to check everything !

The simplest way, to minimize collision detection, is to use a grid (2 Dimensional for Games with Landscapes, and 3 Dimensional for ones in Space for example).
Now keep the information in which Sector an Object is, and update it everytime it moves from one Sector into another.
Now in your main Gameloop, where you process all Objects, you check it only against Objects in the same Sector, and the neighbouring Sectors (a Object can be in up to four Sectors at the same time). With that you minimize your collision checks dramatically, you can optimize that be using an more dynamic Grid (Octrees, Quadtrees) where you split up each Sector in even smaller Sectors, if it contains more than one Object. If you wan''t to do that depends on how fast you wan''t it, and how much time you have for implementing it


Lars
--------> http://www.larswolter.de <---------
Sounds simple enough
But what about the checking the "2D" mouse against 3D objects in IM (IM dose not have the RM Pick)
I know I have to do a PointInPoly, but is there anyway to get the transformed polys after a call to DrawPrim ?
You could make an inbetween Step, by transforming with ProcessVertices, but that isn''t efficiant, and not good whith TnL Hardware, so make it the otherway, transform your Mouse into 3D, so you get a line, and you can get the intersection between line and Polygon.
The transformation from 2D to 3D shouldn''t be very complicated, cause you know your Projection Matrix and so on.

Lars
--------> http://www.larswolter.de <---------
Hi Drki,

Regarding your last post (about the ''400 objects''), you should realise that you don''t test for collision between stationary objects such as walls and doors (when is a wall going to ever collide with another wall on the other side of the level ). You only need to test for collision between each moving object and other objects (moving or stationary)... however, it is pointless to retest something you know to be true: if a collision test has been performed between to objects, why test the reciprocal collision?

e.g. if(A collides B){ do this.... }
if(B collides A){ do same thing... }
There is no point in doing this test twice...

I suggest you do what others have suggested and look into bounding sphere/box techniques in various articles (sorry, I''m too spaced out at the moment to explain stuff, and I''d probably bollocks it up )

-------------
squirrels are a remarkable source of protein...
Thanks, guys.
I am starting to get theoretical part.
Now if some of you have some samples somewhere dont hasitate(or something) to send them to my mail.

(lots of ''some'' in my text. hm)


This topic is closed to new replies.

Advertisement