PDA

View Full Version : HitTest/ Collison Detection in 3D?



booeriis
October 20th, 2007, 04:54 PM
hi everyone

i'm really stumped on how to implement some hitTesting or collision detection in this 3D environment.

its based off some of the tutorials from here but modified a little to suit my needs.
anyway, the style is supposed to be something like Diablo or Fallout, where the player walks around viewed from above (almost), but can also walk behind things and i need the player to be able to collide with these objects, be they builings, items, or people. but more important than just testing to see if they hit them, how can it stop the player moving when walking into a wall for example.

if anyone can help i'll give you a special credit when it's finished (it's part of my university course)

thanks
Booeriis

Jerryscript
October 20th, 2007, 09:11 PM
It depends upon how precise you need your collision detection to be. The simplest method is good ol pythag's theorem. Treat each object as a sphere with a radius that encloses it completely. Then calculate the distance with

dist^2 = (x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2

If the distance is less than the sum of the two sphere's radii, then there is a collision and you need to alter the appropriate vector factor.

Sirisian
October 20th, 2007, 10:51 PM
Diablo and Fallout are 2D in respect to collision detection. That should make things easier for you.

You can use the separating axis theorem:
http://gpwiki.org/index.php/VB:Tutorials:Building_A_Physics_Engine:Basic_Inter section_Detection
Then look into the minimum translation distance theorem for collision response.
Just find the minimum penetrated amount along a normal basically and move the object that much. Works well for most simple games.

booeriis
October 21st, 2007, 11:23 AM
thanks for the replies you guys. i think both of those are a little out of my legue (i havent doen anything to do with maths since i was 16) but it's definatly food for thought i'll see what i can do with it. if you're right about diablo and fallout having 2D collision detection then i may have a think about how i can do it that way rather than using loads of maths thaat i don't really understand

thanks anyway!