#### Archived

This topic is now archived and is closed to further replies.

# sliding

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

## Recommended Posts

it''s a miricle i have my 3d collision detection working. now all i need to know is how do you make the player slide along the wall. my game is a first person game and i want it so when the player hits the wall he slides along it if there still pressing forward. can someone tell me how to do it or tell me a good tutorial that tells you how to?

##### Share on other sites
I assume that when the player goes "inside" a wall, you bounce her back to the previous position. You should get the normal vector of the wall, and bounce her back in that direction.

In other terms, when the player has penetrated a wall, you don''t go back the same path, you find the shortest way out of the wall instead.

##### Share on other sites
i have a normalized normal of the triangle and a player vector. what do i do to to move the player back along the normal.

##### Share on other sites
Calculate a line between where the player is and where the player should be if they moved unobstructed. Then caculate the point where that line intersects with the wall and place the player there.

##### Share on other sites
quote:
Original post by m_wherrett
Calculate a line between where the player is and where the player should be if they moved unobstructed. Then caculate the point where that line intersects with the wall and place the player there.

and how would this be supposed to result in any kind of sliding?

##### Share on other sites
This will make sliding because the player will enter the wall, and then be pushed out -- but the only thing that is rendered is the part where the player is pushed out, not when they are inside the wall. So when they are at an angle, say the left arm enters the wall. The left arm is pushed out, but the player still moves foward and left towards the wall. This looks like sliding to the player.

##### Share on other sites
No, that method disregards all movement by the player after the first point of contact during a particular time interval. In otherwords, it neglects to implement the actual "sliding" part of sliding a long a wall. The first poster is correct; bounce them back along the wall''s normal vector until they are outside the wall.

What you would have to do to make the 2nd suggestion work is after placing the player at the point of contact, move them the remaining distance in their movment vector that is parallel to the wall (dot product of their remaining movement vector and a vector parallel to the wall in their movement direction)

##### Share on other sites
Heh, I didn''t read the middle of the thread closely, so I was thinking we were still talking about the first method (moving outward along the normal). I agree, the second way won''t work.

##### Share on other sites
You can''t just move it back along the normal because this could push your object through a wall if it is in an acute corner.

You could do something like this.

Find the first collison, then calculate a new destination and do a collision test from the location of the first hit to the new destination. To calculate the new destination you just project the original destination onto the plane of the polygon hit. This will allow you to slide along walls.

float dot;
PLANE hit_plane;
VECTOR3 start;
VECTOR3 end;
VECTOR3 new_end;

dot = end.x*hit_plane.n.x+end.y*hit_plane.n.y+end.z*hit_plane.n.z;
dot = -dot - (hit_plane.d-SMALL_EPSILON);
new_end.x = end.x + plane.n.x*dot;
new_end.y = end.y + plane.n.y*dot;
new_end.z = end.z + plane.n.z*dot;

##### Share on other sites
Check the BSP tutorial 7 in Gametutorials. It handle sliding and clamping. Also include a descriptive html about that topic.

http://www.gametutorials.com/CodeDump/CodeDump_Pg1.htm

Cheers
fpuig

1. 1
2. 2
Rutin
19
3. 3
khawk
19
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633771
• Total Posts
3013762
×