This topic is now archived and is closed to further replies.


collision problem

Recommended Posts

i'm useing the plane collision detection in the book open gl game programming. but when the top of the triangle is sloped it doesn't work. sometimes is pushes you up to early sometimes it does nothing. my collision detection works fine when the wall is vertical. heres the code i use for collision detection. //this is done in initalisation since the walls never move; //tri[] is an array of wall data used to draw the walls and do collision detection. for(int f=0;f<100;f++) { if(tri[f].point2[0] == NULL) break; tri[f].vector1[0] = tri[f].point1[0] - tri[f].point2[0]; tri[f].vector1[1] = tri[f].point1[1] - tri[f].point2[1]; tri[f].vector1[2] = tri[f].point1[2] - tri[f].point2[2]; tri[f].vector2[0] = tri[f].point2[0] - tri[f].point3[0]; tri[f].vector2[1] = tri[f].point2[1] - tri[f].point3[1]; tri[f].vector2[2] = tri[f].point2[2] - tri[f].point3[2]; tri[f].normal[0] = tri[f].vector1[1]*tri[f].vector2[2] - tri[f].vector1[2]*tri[f].vector2[2]; tri[f].normal[1] = tri[f].vector1[2]*tri[f].vector2[0] - tri[f].vector1[0]*tri[f].vector2[2]; tri[f].normal[2] = tri[f].vector1[0]*tri[f].vector2[1] - tri[f].vector1[1]*tri[f].vector2[0]; tri[f].length = float(sqrt((tri[f].normal[0]*tri[f].normal[0]) +(tri[f].normal[1]*tri[f].normal[1]) +(tri[f].normal[2]*tri[f].normal[2]))); for(int counter=0;counter<3;counter++) tri[f].normal[counter] /= tri[f].length; } //this is called to test for collisions with triangles near to the player. void collision(triangle trian) { float d;//distance of the plane from the origin float d2; float d3; float distbefore;//current distance from the player to the plane float distafter;//destination distance from the player to the plane d = (trian.normal[0]*trian.point2[0])+ (trian.normal[1]*trian.point2[1])+ (trian.normal[2]*trian.point2[2]); d2 = (trian.normal[0]*plone.point1[0])+ (trian.normal[1]*plone.point1[1])+ (trian.normal[2]*plone.point1[2]); d3 = (trian.normal[0]*plone.point2[0])+ (trian.normal[1]*plone.point2[1])+ (trian.normal[2]*plone.point2[2]); distbefore = d-d2; distafter = d-d3; if((distbefore > 0.0 && distafter < 0.0)|| (distbefore < 0.0 && distafter > 0.0)|| (distbefore > 0.0 && distafter == 0.0)|| (distbefore < 0.0 && distafter == 0.0)) { plone.point2[0]+=(trian.normal[0]*plone.speed)*deltime; plone.point2[1]+=(trian.normal[1]*plone.speed)*deltime; plone.point2[2]+=(trian.normal[2]*plone.speed)*deltime; coll=true; } else coll=false; } can anyone tell me whats wrong with that to make it not work if the triangle is sloped. it works if it's on an angle and verticle. also can someone tell me why it viabrants when moveing on angle to the wall and colliding with it. can someone please help [edited by - hello_there on January 29, 2003 3:52:36 AM]

Share this post

Link to post
Share on other sites