# Sliding along walls

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

## Recommended Posts

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

##### Share on other sites
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.

##### Share on other sites
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).

##### Share on other sites
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...

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.

##### Share on other sites
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.

##### Share on other sites
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 :)

##### Share on other sites
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. :)

• 21
• 13
• 9
• 17
• 13