Skip to main content
GameDev.net gamedev.net
🔒 Locked

how do you?

Started by hello_there Jan 23, 2003 at 10:22 PM 1 replies 200+ views
Original Post
hello_there
hello_there
i''ve got my collision detection working but now i want to know how to do some collsion responce. i want the player to slide along the wall when they hit it. for eg when you hit a wall i don''t want the player to just stop i want them to slide if the player isn''t at right angles to the wall. like on the 3d zelda''s when you hit a wall the player slides along it if there not at right angles. anyone know how? my collision detection uses dot product and cross product if you need to know that.
____________How could hell be worse?
Kuladus
Kuladus
your code should just eliminate the velocity component in the normal vector of the wall face

do u have some code to show?
hello_there
hello_there
here's my collision detection code no coments but i'll right them in soon.

//point1[] is the current position of the player
//point2[] is the destination of the player
//0 = x 1 = y 2 = z

//these line are put in after collision detection
//plone.point1[0] = plone.point2[0];
//plone.point1[1] = plone.point2[1];
//plone.point1[2] = plone.point2[2];

void collision(triangle tri)
{

tri.vector1[0] = tri.point1[0] - tri.point2[0];
tri.vector1[1] = tri.point1[1] - tri.point2[1];
tri.vector1[2] = tri.point1[2] - tri.point2[2];

tri.vector2[0] = tri.point2[0] - tri.point3[0];
tri.vector2[1] = tri.point2[1] - tri.point3[1];
tri.vector2[2] = tri.point2[2] - tri.point3[2];

tri.normal[0] = tri.vector1[1]*tri.vector2[2] - tri.vector1[2]*tri.vector2[2];
tri.normal[1] = tri.vector1[2]*tri.vector2[0] - tri.vector1[0]*tri.vector2[2];
tri.normal[2] = tri.vector1[0]*tri.vector2[1] - tri.vector1[1]*tri.vector2[0];

tri.length = float(sqrt((tri.normal[0]*tri.normal[0])
+(tri.normal[1]*tri.normal[1])
+(tri.normal[2]*tri.normal[2])));

for(int counter=0;counter<3;counter++)
tri.normal[counter] /= tri.length;

float d;//distance from origin
float d2;
float d3;
float distbefore;
float distafter;

d = (tri.normal[0]*tri.point1[0])+
(tri.normal[1]*tri.point1[1])+
(tri.normal[2]*tri.point1[2]);

d2 = (tri.normal[0]*plone.point1[0])+
(tri.normal[1]*plone.point1[1])+
(tri.normal[2]*plone.point1[2]);

d3 = (tri.normal[0]*plone.point2[0])+
(tri.normal[1]*plone.point2[1])+
(tri.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))
{
coll=true;
}
else
coll=false;
}

[edited by - hello_there on January 24, 2003 7:24:33 PM]
____________How could hell be worse?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.