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

Collision Detection & Sliding along walls and surfaces

Started by LabRat404 Dec 9, 2004 at 10:27 PM 4 replies 1.7k views
Original Post
LabRat404
LabRat404
I realize I've typed a lot of text here, so if you just want the bottom line: "when a collision is detected, how do I calculate the destination point projected onto the plane that has been intersected? (in order to create a vector from this point and the intersection point)" I've googled the hell out of this, and even searched these forums. I found just what I was looking for, and I know exactly what I need to do....but the problem is, I don't know how to do it. here are the details: I've got a very good collision detection method ( until I make it better :), as I've never been able to run through a wall or a corner that I'm not supposed to. what I'm trying to do is slide along surfaces instead of "sticking to them". I'm sure you all know what that means. I've got most of the code to do it, but I can't seem to figure out how to calculate the "destination point projected onto the plane". I was able to do this with pencil and paper, but I think I just had a very lucky error, as it did not work twice. all I need is to figure out how to project the destination point onto the plane in which the start position would have intersected, and take the intersection point and the projected point and get a vector, and from there, is cheese. things you may need to consider: my camera is not yet bounded by any polyhedron, its simply a vertex that floats around to world. I figured I'd get all the vertex calculateions down before I get any more complex than that. my "camera vertex" never coincides with a plane. I've coded my collision detection so that you can only get very very close to is, but never coincide. so there will be occasions whenthere is a zero distance between the player and a plane. whew.
0x52 0x65 0x61 0x6C 0x69 0x74 0x79 0x43 0x72 0x61 0x73 0x68
Ademan555
Ademan555
why not reflect it along the plane's normal? you could even multiply the component comming away from the plane V * N by some sort of elasticity coefficient so that it could just slide if that coefficient was 0, i could give you the actual maths for that if youd like, but atm i dont wanna dig them up as im lazy, if your interested just say so and ill grab em

(note: i cant take any credit for the idea, i learned from one of oliii's tuts)


hope that helps
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out hi
LabRat404
LabRat404
point me in the direction of Olli's tutorials then :-)

I'm not sure what you mean by reflecting it to the normal or whatnot... but if I have the point of intersection, and then I have the point of original destination projected onto the plane, I'd have the vector of my new direction of movement.

then I'd calculate my new velocity by finding the angle of the new vector to my original vector of movement(which is my angle of movement to the wall when I hit it), and subtract it from 90. like if the angle was 90, 90 - 90 s zero. 135 - 90 is 45. 90 is collision perpendicular to the wall, which means no sliding. if my collision was 45 degrees, I'd be at a -45 degree angle. at that point, I'd devide what I just worked out by 180 (which is one degree higher than the max angle I could get) to get a percentage, and multiply my velocity by that. that way, I get a percentage of velocity based on the angle that I hit the plane on.

that was my idea that I concoceted myself. is that too much work?
0x52 0x65 0x61 0x6C 0x69 0x74 0x79 0x43 0x72 0x61 0x73 0x68
Kwizatz
Kwizatz
Asuming your doing ellipsoid-triangle collision detection you can find the distance from the ending position (the ending position had the ellipse not collided) to the triangle's plane, then move that much from the ending position folloing the triangle's direction, that will leave the ellipsoid right at the triangle's plane, then move the size of the ellipsoid collision radius allong the normal again, which will place the ellipsoid in the correct position.

Check here
LabRat404
LabRat404
I'm not doing the elipsoid stuff yet. because I'd also like to be able to have objects use the same collision detection methods for sliding, and bouncing if the collission occurs at a great enough velocity based on the object's preset "elasticity" or some other modifier along with its mass. basically, I want realistic physics. I considered using a player model for the game, even in single player mode, and detecting collisions for each of the models vertice...but then I realized that in high poly models, that would be a lot. now I'm not sure what to do...

I also thought about flexable models, in that when a player is dead, his model will flop around. I thought about perhaps making each joint of the model have a portion of the entire weight of the model and exerting gravitational force and checking colisions for each joint....but how to keep the model itself from half intersecting walls...
0x52 0x65 0x61 0x6C 0x69 0x74 0x79 0x43 0x72 0x61 0x73 0x68
Ademan555
Ademan555
http://uk.geocities.com/olivier_rebellion/Polycolly.zip

its a great tutorial, one thing to watch for is he changes dot product in his pseudo-code from Dot to . about halfway through, not a big deal, just a warning :-D. Also, the thing you want is about 2/3 down the page called "2d polygon.html" iirc remember, the reflecting about a normal part is applicable to 3d as well as 2d

hope that helps
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out hi

Topic Locked

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

Sign in to reply to this topic.