Sliding along walls

Started by
5 comments, last by Absolution 19 years, 7 months ago
This is more of a confirmation than anything. I'm working on a simple 3D engine and have just implemented some rudimentary collision detection with the walls. Basically, what I've done is represent the camera as a sphere and test for intersection with the triangles in the map. I just take the position before and after moving and if there is an intersection I stop the camera a certain distance from the wall. This works beautifully, except I have sticky walls. :) I'm about to add sliding to the collision detection and I was wondering how most go about this. What I plan on doing is calculating a vector along the wall with length proportional to the angle between the view vector and the wall normal (i.e. if you run directly into the wall the resulting vector would be 0). This makes sense to me, the only thing is I would have to again test that vector with triangles in the area in a cyclic fashion and I would have to watch for cases like corners. You can check out the latest version at (requires java 1.1 and I am aware of some performance issues, but I've yet to work out some java timing problems): http://www.freestandingentertainment.com/chance/test3
Advertisement
Haven't done anything like this but...
I would try to do what you say - remove the part of the 'movementvector' that is parallel to the normal of the plane.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~I'm looking for work
yeah, that's how you do simple sliding. as fdor equations...

new_vel = vel -(vel.DotProduct(normal)) * normal;

[-(vel.DotProduct(normal)) * normal] removes the normal component of vel from vel.

to be more fun, you can do

new_vel = vel - (1.0f + elasticity) * ((vel.DotProduct(normal)) * normal);

where elasticity is between 0 and one. 0 means sliding (no bouncing), 1 means full bounce (the velocity is reflected fully of the wall, no loss of momentum).

Everything is better with Metal.

You might as well sooner than later give up on the simple collision detection and implement the "real" thing. You will need to do that eventually in any case, if you want a serious engine...

I suggest you read about sliding.

The best paper I found was this one from Peroxide.

www.peroxide.dk/papers/collision/collision.pdf




PS: He talks about ellipses. I would just ignore that part for now. The math is exactly the same, all he does, is altering the collision space, so the sphere is squeezed together to an ellipse.
Circles work just as well. If you make that work first, then you can look into ellipses at some point, if you feel the need for your object to move closer to the walls.
Quote:CalvinI am only polite because I don't know enough foul languageQuote:Original post by superpigI think the reason your rating has dropped so much, Mercenarey, is that you come across as an arrogant asshole.
Thanks for the input. Well, by simple I meant I was testing with all triangles. It's a proper sphere/triangle collision test. If by the 'real' thing you mean what was done in that paper, then that's what I've done. I might add a cylinder test later.
ah ok, when you said simple, I assumed you did no sweep test, but only tested the object for collision each frame.

Your system isn't that simple then :)
Quote:CalvinI am only polite because I don't know enough foul languageQuote:Original post by superpigI think the reason your rating has dropped so much, Mercenarey, is that you come across as an arrogant asshole.
Ya, now that I think about it, it did take some work to get it working properly. There were a few versions that would get me 'stuck' in the walls. :)

This topic is closed to new replies.

Advertisement