Jump to content
  • Advertisement


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


Terrain Walking

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I now reached a point where everything get''s tricky. After I coded some Collision-Detection-Response system for polygons that have a angle of 0° or 90° to the movement vector I now want to implement a way to do proper terrain walking on uneven landscapes. I tried already a version with calculating slopes for every polygon an than add then muliplay this value with my movement value but It just workd properly in the xy plane. I want to know what''s the normal, prober way to do this. Does it really work with slopes for XY and YZ of a polygone (that seems a little to much work, because you have to seperate every time your rotate etc.).

Share this post

Link to post
Share on other sites
I'm not sure what type of surface you have, but I'll assume a plane, i.e. flat surface. The equation for a plane is a*x+b*y+c*z=d. The vector (a,b,c) is called the normal to the plane. Three points define a plane, just like to find your slopes you need three points. If you call those points p1, p2 and p3 then A normal is (p2-p1)x(p3-p1) where "x" is the cross product. There are an infinite number of normals all pointing in the same or opposite direction. You generally want a normal pointing up from a surface and you want it to have a magnitude (length) of one. If you draw a triangle connecting the three points and look down on it from above the points are either numbered clockwise or counter-clockwise. Which way they are numbered is going to determine which way your normal points. You want them numbered in a direction that makes the normal point up. You get it to have a length of one by normalizing the normal or in other words by dividing each component by the magnitude of the vector. The magnitude of the vector (x,y,z) is sqrt(x^2+y^2+z^2).

Now you have a unit normal. a*x+b*y+c*z is the dot product of the vectors (a,b,c) and (x,y,z). So d=n.p where n is the normal, "." is the dot product and p is ANY point in the plane. d is the directed distance of the plane from the origin and d-n.p is positive if a point is one side of the plane, negative on the other and zero if it is in the plane. If you have a unit normal that will tell you which side a point is on and its distance from the plane. Not particularly relevant here, but might come in handy for other things. So now you have a representation for the plane.

Some direction is forward for the player and another direction is up. Those can be represented by vectors. The cross product of those two vectors points right, or left depending on which way you do the cross product. You want the players up vector to point in the same direction as the normal of the surface they are standing on. Well, if they were standing you wouldn't, but if it is a vehicle you would. You want the forward and right vectors to be parallel to the surface. The temp right vector is the cross product of the new up vector and the old forward vector. The new forward vector is the cross product of the temp right vector and the new up vector. The temp right vector can be discarded, but if you want to keep a right vector then the new right vector is the cross product of the new up and new forward vectors.

I don't know how much that helps since I don't know how much of that was "well duh" and how much was "say what?" If you didn't have any idea what I was talking about then it is either because of the way I said it or because you need to refer to the Articles & Resources section of this site. It should give you enough to figure out which articles you need to read.

[edited by - LilBudyWizer on May 5, 2002 10:12:44 PM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!