Sign in to follow this  
Absolution

Sliding along walls

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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...

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.

Share this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this