   walking on a slope in a terrain
  I've made a terrain and a camera that walks over it. However I would like to implement some physics so that when the camera is on a slope it will start to fall down. My idea was to use a vector in the direction of the slope of the current polygon the camera is on. But i'm having trouble getting this vector. I thought of using the up vector of the camera and a vector representing gravity.Hope that makes sense.Can someone point me in the right direction maybe a sample or tutorial? How is this effect usually done in games?thanks in advance   
  Presumably, you have a collision system to get the height of your camera.  You need to be able to get the information about the poly you have 'collided' with.  This will be dependent on your engine/collision system.You will need either the normal of the face you are on, or the co-ordinates of the points that make up that face.  You can use these to obtain the angle of the surface.  You may find it easier to think in terms of components (x and z say).  The lateral(sideways) force you need to apply will be given by m*g*sin(angle), where m is your mass, g is the acceleration due to gravity and angle is the angle between 'up' and your surface.You will also need to think about friction.   ;  Thanks for the reply.Yeah I have collision all set up, the camera rests on the inclined surface poylgon and I know the normal from the 3 vertex points and the camera's xyz position. What I wanted was the camera to move down along the incline the polygon makes. So basically the camera is at point (x,y,z), on the next frame move it down along the slope to (x',y',z').   ;  I understood you want to compute a vector pointing into the direction to where the camera should slide down a slope. I don't know whether the following is the best solution, but it should work.Assuming your terrain is spreaded in the x-z plane, so that its height is along the y axis. When looking at the normal of particular polygon of the terrain, you could get several informations from it:(1) You could get the slope angle from the dot product of the normal and the principal y axis. With this you could compute the velocity of sliding, inclusive whether the slope is great enough to overcome friction (if you want to do so).(2) If the camera _is_ sliding, you need to know not only it is going down (say towards negative y) but also in which heading direction (say x and z co-ordinate). You could determine the principal heading from the normal also: Project the normal onto the x-z plane by setting the y co-ordinate to zero. Notice that this will result in zero vector in case that the polygon isn't sloped, but then there is no sliding at all.You could project the principal heading vector back onto the terrain's polygon to determine the sliding vector upon the current polygon. Normalizing  and scaling that vector properly with the determined sliding speed yields in the current velocity vector.To project the sliding vector s onto the polygon you could do so: Assuming your polygon is given by the plane equation( P - O ) dot n = 0where O any point of the polygon and n its normal. Choosing a point in direction of s, e.g. s + O, as the origin of a ray, and letting the ray travel down -y (the direction of gravity)R(t) := O + s + t * [0,-1,0]^TSetting this into the plane equation, since we want to know the projected point onto the plane( O + s + t' * [0,-1,0]^T - O ) dot n= ( s + t' * [0,-1,0]^T ) dot n= s dot n - t' * ny = 0<=> t' = ( s dot n ) / nyWith this t' and R(t') and the differenceR(t') - O = s + t' * [0,-1,0]^Tyou see that only the y co-ordinate is affected (and the orig. sy is 0), what is ok:s' := [sx, - ( s dot n ) / ny, sz]^T As already said, normalize and then scale s' by the current sliding speed.However, you must check whether the new position is still on the same polygon or else does already touch a neighboured polygon. In the latter case you have to correct at least the height of the position of the camera, of course.P.S.: Something complicated. Please check it for correctness.   ;  after looking through that i'm still a little confused.I understand what your trying to do but am little confused with the equations.thanks anyway.[Edited by - rogueAgent on December 9, 2005 6:14:13 AM];  [x,y,z]^T simply means a column 3D vector written in row kind (hence the T for "transposed").(I will explain it with some more words, even if it looks like to explain the theory again, I need this _why_ the formulas look like they do.)The equation of the plane (as generalization of the polygon of interest) is called "Hesse'sche Normalform" in german. Don't know the english term for that. From it the possibly well know formA * Px + B * Py + C * Pz + D = 0could be derived by( P - O ) dot n = P dot n - O dot n = 0if settingA := nxB := nyC := nzD := - O dot nSay: Any point P lies exactly in the plane if its distance along the plane's normal is zero.Now I suppose to pick a point on the polygon. For ease I picked O what is (see above) called the "origin" of the plane. Let it be any of the vertex positions of the polygon.Next I suppose to go away from that point by the flat sliding vector s, so that a point O+s somewhere above the polygon occurs. If looked straight from above, this new point seems to be part of the wanted sliding vector. But the real sliding vector does not go to the air but upon the polygon. So I suppose to add a variable part to it, that translates the point down:( O + s ) + t * [0,-1,0]^T =: R(t)This is in fact the formula of a ray with the variable t. The ray describes all points on a straight perpendicular line going through O+s, so it will also contain the hit point on the plane. Since the hit point will have a zero distance from the plane, setting the ray's formula into the plane equation, and solving for the variable t will yield in that t' that is valid at the hit point:t' = ( s dot n ) / nySetting this into the ray's equation yields in the hit point itself. However, we don't want the hit point itself but the direction vector upon the plane. Computing the difference of the hit point and the origin of the plane (both are defined to lie upon the plane!) will do the trick:R(t') - O = s + t' * [0,-1,0]^TConsidering the both zeros on the right side, and setting in t', and also considering that sy is zero by definition (we have done so at the projection of the normal onto the principal x-z plane), this could be written ass' := [sx, - ( s dot n ) / ny, sz]^T Moreover, as I've not written in my previous reply, since s is [nx, 0, nz]:s' := [nx, - ( nx^2 + nz^2 ) / ny, nz]^T As code:float x = getNormalOfPolygon().x;float y = getNormalOfPolygon().y;float z = getNormalOfPolygon().z;Vector3 slidingVector = Vector3(x, -(x*x + z*z)/y, z);// normalize and scale by speed hereOk, this seems very simple for such a big couple of math, but I have derived that from scratch, so I still suggest you to check its correctness.For a straight flat polygon the sliding vector will become (0,0,0) what is ok. For a 45 degree polygon to the right it will become like (1,-1,0) what is also ok. For a straight down polygon it is not computable since there is no sliding but a falling (no contact) what is also ok.   ;  thanks haegarr that cleared it up :)The only thing I was unsure about was the addition of the points O and s and setting s to normal but with y=0.Thus only nx and nz are needed to determine a new position for the camera on each frame. This implemented works great.   