# 3D Terrain collision detection help-mdx c#

## Recommended Posts

Iv been working on collision detectection as the name implys and im working on a sphere collison for a terrain that can also be applyed to an enclosed level (like a building). Iv been reading lots of articles on collision detection and in particualer this article on collision detection useing elipsoids http://www.gamedev.net/reference/articles/article1026.asp (matter of fact my main subject of game is a ball ) although i dint follow the artical exactly (which im now regreting) but i have the feeling im not far off because most of the collision parts concepts of the artical is there but then again i have no idea what might be wrong maby i need to normalize something. So im asking for some help some segestion or fix to my code or even a new tutorial that can give me a difrent perspective on the problem oh and as i write this artical i see a logical error if i collide with even a floor (with gravity included) i wont beable to move foward at all maby if i calcualte collision and gravity velocityts sepratly... eh nm lets just get it working. I sould also methion what happens with this code I guse the most recent problems im not geting any type of collision but in past i have had problems when i was collideing when i souldent be collideing.

//above hear i figure out which verts posibly collide and add there indices to a list to keep track of faces
for (int i = 0; i < inds1.Count -3; i+= 3)
{
Vector3 point1 = (vertsRef[(short)inds1[i]]).Position + offSet;
Vector3 point2 = (vertsRef[(short)inds1[i+1]]).Position + offSet;
Vector3 point3 = (vertsRef[(short)inds1[i+2]]).Position + offSet;

Plane p = Plane.FromPoints(point1,point2,point3);

p.Normalize();

Vector3 startPoint = obj.Position;
Vector3 endPoint =  obj.Position + obj.velocity;

Vector3 vec = Plane.IntersectLine(p,startPoint,endPoint);
// Vector3 closestPoint = closestPointOnTriangle(point1, point2, point3, vec);

if (vec.Equals(Vector3.Empty)&&!PointInTriangle(vec, point1, point2, point3))
{
//do nothing
}
else
{

//what to do if we collide if any thing
return;
}

}
//if we never collide with any thing
//move
obj.Position += obj.velocity;
obj.velocity = new Vector3();


thanx for helping me out

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627704
• Total Posts
2978716

• 21
• 14
• 12
• 10
• 12