Sign in to follow this  
fguihen

collission detect inside a mesh

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Shadx

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this