# collission detect inside a mesh

This topic is 5040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i created a room mesh in 3DS max, and exported it as a .x file. i have a simulation of a person running round in it in my c# app. the problem is i dont know how to make the person detect when he hits a wall and not pass through it. i have my charachters bounding sphere, but i cant see how to get the bounding sphere of a each wall, and that wouldnt help anyway. anyone advise me on how to solve this problem?

##### Share on other sites
I'm a newbie with physics myself, but maybe this might help:

You can probably model this in 2D because I'm assuming your walls are all vertical planes... So for each wall, get 2 points, P1 and P2. Using those points you can define a line. How to actually get those points, I'm not sure :/

For your person running around, you can define his collision attributes as his position X and some radius R. Now, write or google for a "distance from point to line" function.

Now you code will look like this:

while( game is not over ){   oldPos = guy.Position   MoveGuy()      collisionOccurred = false   for each ( wall )   {      if( GetDistance( guy.Position, wall.Line ) < guy.Radius )      {         collisionOccurred = true      }   }   if( collisionOccurred )      guy.Position = oldPos}

This is a really simple and crappy way, but oh well hope it helps :)

EDIT: also I just thought, if your room is a simple rectangular solid, you could simply get the bounding box of the room and then compare the character against the boundaries directly...

##### Share on other sites
What I would do is just check every triangle in the mesh against the person's bounding sphere. I think D3DX has a function for this (and if it doesn't there should be plenty of references online). If this becomes to slow (to many triangles to check against), you could probably implement some octree type culling for your collision detection.

##### Share on other sites
There shouldn't be a need for a bounding sphere on your wall. Your looking at an intersection test between a Sphere and a plane. check out

http://www.gamasutra.com/features/19991018/Gomez_1.htm

##### Share on other sites
i cant use intersection between a sphere and a plain as my walls are not straight. they have curves and big semi circles along their length. i think il try comparing each triangle in the wall mesh with my persons bounding sphere. one question though. will the floor part of the mesh that my person is walking on not interfere, as the floor will always be inside the bounding sphere, from what id imagine?

1. 1
2. 2
3. 3
frob
20
4. 4
Rutin
19
5. 5

• 32
• 13
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
632558
• Total Posts
3007077

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!