Sliding collisions question

on www.gametutorials.com there is a tutorial on sliding collisions that takes this approach:

Assume that nothing exists in the world except triangles (a fair assumption in OpenGL for sure).

Collision-check every single triangle in the world one at a time with the camera (his simple example didn’t involve octrees or BSP trees but I’m sure they could speed up the processing).

Let’s call the minimum distance the camera should be from any surface “radius”. As each triangle is checked, if the camera is more than 0 units but less than radius away from it, move the camera along that triangle’s normal until it’s radius units away.

A very simple, very well-defined approach. I have 2 questions:

  1. Am I correct that if the camera’s velocity is greater than radius, it’s possible to go from the front of a surface to all the way behind the surface, bypassing the region in which the collision check would take place? Off the top of my head, you could keep an array of distances last frame and then you collision check would be, was it more than radius last frame and less than radius this frame? And then move along the triangle’s normal until he’s radius units in front of it. I can’t think of a better solution than that.

  2. I believe (and I’ve asked him to verify) that if 2 triangles have an acute angle between them that the results might be unexpected. This is hard to explain without a picture so I won’t write a book, but I do believe that an acute angle will throw this off, and it seems to me that a rigorous solution that guarantees sliding the user out to a point that’s radius units in front of every triangle could get very complicated - for example, if he’s walking inside a cone.

Any thoughts on #1 or #2 here? Anyone else encountered this?

Thanks.

  1. This problem is solved by additionally checking the position of the object in the frame before. If the distance is negative now and was positive one frame before (or the other way round), you had a collision somewhere between the frames and you have to react apropriately.

  2. A simple solution for this problem is to check for collisions after moving the object until there are no new collisions detected. This should get you out of any corner, provided there is enough place to go to somewhere nearby, but if there isn’t, you shouldn’t have been able to get to this point, right?

Your answer to #1 is what I was thinking too. Thanks for confirming!

Your answer to #2 is an interesting idea. I don’t think that just going back to the beginning of the loop would work. It’s really hard to explain without a picture, but I’ll try:

Imagine two triangles perpendicular to the XZ plane with a 10-degree angle between them. Imagine the camera moves one unit per frame and the sliding collision distance is 2 units.

There is exactly one point exactly 2 units in front of both triangles. Imagine the user is walking along the line that bisects the two triangles and by a bizarre coincidence he lands right on that spot. His next step takes him inside “the collision zone”.

I drew some diagrams, and it seems to me that if you just pushed him perpendicular to one triangle, then the other, then the other etc. that you’d never get to the one point that’s 2 in front of both of them - you’d get closer and closer and closer but never get there.

Maybe I’m wrong though, I’ll keep thinking about this.

Thanks
DTXCF

I’ve also used the approach Overmind suggests, namely to invoke the collision detection routine recursively while sliding. To avoid getting into tricky situations with this approach, you can cap the number of recursions at some small maximum (say three or four). If you’re still not in a clear spot after that, just move the user back to the position where the very first collision occured, and stop him there.

This means you get jammed if you touch to many surfaces at the same time. Of course you can still turn around and move away yourself, you just won’t slide anymore if you keep trying to move forward.

– Tom

thanks for the thoughts guys - I’ll try these.