Jump to content
  • Advertisement

Archived

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

how do you?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!