Doing the wall slide thing

Member
Posts: 353
Joined: 2002.04
Post: #1
I'm trying to set-up the movement code in my game so that the player slides along an impassable wall as happens in most 3D games. If I have the code working to test the player's movement vector's collision with a triangle (which is the impassable wall), how do I then determine what would be the right vector to have the player slide along the wall?
Quote this message in a reply
Zoldar256
Unregistered
 
Post: #2
Let the current direction of movement be V.
First get the normal vector for your triangle. Call this N
Then get the projection of V onto N. Assuming both vectors are normalized this is V (dot) N times N. Call this projection.. I dunno.. P
The perpindicular movement vector is then V - P.
Quote this message in a reply
Jesse
Unregistered
 
Post: #3
Here's the way it's usually done. Let's say you've moved and your new position is 'inside' a wall. What you do is push yourself (the player, the camera, or whatever) along the normal of the polygon you've intersected by the distance that you are behind it (assuming you're a point - if you're a sphere, it would be the distance plus your radius). As an example, let's say you find yourself behind a wall by a distance of 20 units. Your new position is:

myNewPos = myCurrentPos - (wall.normal * wall.DistanceTo(myCurrentPos));

Or something like that (assuming being behind the wall gives you a negative distance).

This essentially negates the portion of your velocity (i.e. speed plus direction) that 'collides' with the wall, and leaves you with whatever is left. If your velocity is primarily 'into' the wall, there will only be a little left after you negate it, and you'll slide slowly along the wall. If your velocity is primarily along the wall, only a small portion will be negated and you will slide quickly. This is what you intuitively expect, and what happens in Quake, etc.

'Hope that was clear enough. If not, ask and I'm sure I or someone else will be happy to clarify.
Quote this message in a reply
Member
Posts: 304
Joined: 2002.04
Post: #4
Quote:Originally posted by Zoldar256
Assuming both vectors are normalized this is V (dot) N times N.
only N should be normalized - not V. But otherwise correct. Incidentally V - 2.0*P will give you a 100% bounce velocity. So you can mix if you want, i.e., V - 1.2*P will mostly slide - but still bounce you off the wall a bit.

hth
Quote this message in a reply
Zoldar256
Unregistered
 
Post: #5
Whoops, yea, was just pulling those outa my head at the time.
Jesse: Our methods are essentially the same. Minus the fix for my poor math ;-)
Quote this message in a reply
Jesse
Unregistered
 
Post: #6
Quote:Jesse: Our methods are essentially the same.

Yup...I think we posted our replies at the same time :-)
Quote this message in a reply
Member
Posts: 353
Joined: 2002.04
Post: #7
Haven't had the chance to get any work done on it yet, but thanks for all your help guys, will let you know how it goes.
Quote this message in a reply
Member
Posts: 304
Joined: 2002.04
Post: #8
Of course nothing is ever as easy as it seems at first.

After the collision and the slide - you have to test for collisions *again* b/c during the 'slide' you might hit another wall. You also have to test if you hit an edge or a corner - you have to test if you are touching 2 (or more) walls at once. IMHO its really hard to get right - Good Luck!!
Quote this message in a reply
Member
Posts: 353
Joined: 2002.04
Post: #9
I found a good article on this sort of thing here:

http://www.fluidstudios.com/publications.html

I'm going to try to implement something a bit simpler than what they have, but if it doesn't work out I will have a closer look.
Quote this message in a reply
Member
Posts: 353
Joined: 2002.04
Post: #10
Got the initial wall slide working well, thanks for all the help. Now I've got to move onto all those other tests codemattic mentioned.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Weird OpenGL thing... jfFlash 9 3,791 Sep 13, 2006 08:11 PM
Last Post: akb825
  lighting a big wall Najdorf 4 2,457 Feb 9, 2006 11:59 AM
Last Post: Leisure Suit Lurie
  This thing = way too slow LongJumper 9 4,550 Dec 20, 2004 05:14 AM
Last Post: TomorrowPlusX
  Projection matrix : Strange thing ? Ole 4 3,028 Sep 13, 2003 02:38 AM
Last Post: Ole
  weird thing fat-t 5 3,209 Jul 7, 2003 04:59 PM
Last Post: fat-t