# Collision Response Woes

I posted a topic about this a month or so ago, and didnt get much help. Since then, I’ve gone on to work on other aspects of my engine, but I never got this collision detection problem solved.

I am working in a terrain environment (see screenshots at http://home.earthlink.net/~ioquan/x3d.htm . For now, I have it set so that all polys are treated as “floors”, meaning that you are raised as you walk over them. This works smoothly, but it means the player can climb up mountains. I want to make it so that when you collide with a steep poly (a “wall”), you are slid instead of raised, thus not being able to climb up it. This part I have implemented too, but I cant get the glitches out of it. The problem is that when the player is colliding with both a wall and a floor, the player bounces erratically.

My models have a position and a velocity. After I have calculated the raw velocity for the model, I test to make sure that the point you are trying to move to does not collide. If it does, I alter it.

What I do is make a line segment from the position to the point you are trying to move to (position + velocity). In the case of floors, I just test to see if the new point is under the poly. If it is, I raise the player to the level of the floor. For walls, I see if the line segment intersects the poly. If it does, I go from the point you are trying to move to (which is behind the poly) along the normal vector of the poly until I intersect the poly. That intersection point is the corrected point that you will move to, and it causes the desired sliding effect. However, there is something wrong with my method, because often when you are colliding with more than one wall poly, or when you are colliding with both a wall and a floor, there is an unwanted bouncing effect (the player bounces between two or more points very rapidly).

If you can offer suggestions on how to get this working smoothly, that would be appreciated.

[This message has been edited by ioquan (edited 07-25-2002).]

I just updated the zip file on my site, and I moved the link to http://home.earthlink.net/~ioquan . If anyone would be interested in taking a look at my code, the collision response stuff is in Facet3D::RayCollide(Point3D * pos, Point3D * velocity); and
Mesh3D::Collide(Entity3D * entity) is also relevant.

It doesn’t look like you are checking for collisions with other walls after you slide the object. This will cause the extreme bouncing, I think…

If you want to slide the object after collision, you’ll have to check for another collision of the object against your tarrain after sliding it. Depending on the framerate, you could check, slide, check, slide, etc. a few times. Then you’ll have to just stop the object at the point of collision.

Good luck,
I think its a tricky problem
Ben Schleimer

hi, i would suggest to look at the collision tutorials at www.gametutorials.com

there is a great one with a spherical collision detection…

your player will climb up stairs etc, automaticly and will slide back when the wall is too hard for him (you know what i mean)

so, i wish you good luck, screenshots are lookin’ cool too!

I dont know if this will help but this is how i do all my collision detection for my player model.

1. Build a bounding sphere around the model (but since my model is never scene, i simply create sphere of a known size)
2. create 3 more bounding spheres, one for the head, one for the body, one for the legs.
3. Using a dot product, test the distance between the initial bounding sphere, and “every” normal on the scene. (plane checks) if there is a collision, check the other 3 spheres for plane collisions.
4. If there was a possitive “plane” collision, we then test all the triangles with that particular normal, on that plane, to see if we have a polygon collision. (a little indepth to go into on this post)
5. If there is a polygon collision, we can then check the angle between the horizon and the normal vector. Depending on the angle, we set a “max” value that the player can walk up.
6. This method works great for with everthing exept a normal vector of (0,-1,0) Because of the whole devide by zero thing. But with a little bit of work, it can be worked around.

Sorry this is so vauge, but CD is VERY difficult, and involved, and i dont have the time right now to lay it all out in detail.

Hi ioquan,
I was looking at your code and engine. Your decision for using gravity & lifting characters( ie: droping into world )leads me to believe you may want not to think of it as a collision detection but rather a gravity issue. My idea would be to kill 2 birds with one stone.-> your rate of fall is a constant at the moment. place in a small acceleration for y(if it’s the gravity component) and scale it to your map. ok now on each frame check what angle you are standing or going and if angle > low incline call a add slide routine to begin slide to add the downhill vector acceleration( x,z ) leaving gravity decide y. this way the longer thay are on the inclide the more thay slide and faster they fall, depending you your +rate(surface dependant) of course.
If you do this it will add a nice effect. This will also give effect of slowing down on small inclines thay you run up. The same idea can be used to slow character fall if jumping off hill. use the angle they land on determine how much energy they loose in one direction and gain in another(just adding more to the same routine ).

I have to say i like the work you have done so far, it works and looks well. Sorry i dident mean to babble on here, im just a bit drunk at the moment and somtimes ramble off ideas.

Caltus

[This message has been edited by Caltus (edited 07-25-2002).]