I am trying to write an application wich moves an object through a 3D terrain, but my trouble is how can I simulate that my object follow the terrain contours, I mean, if my objects go up a hill, it must be follow the hill's orientation and must slows my object speed, since it is going hill up?
Or said in a different way, how can I do to my object match ground slope?
Thanks in advance!
Edited by - ogracian on October 2, 2001 1:58:04 AM
One way is interpolating between terrain triangle vertices to find your altitude (I''m assuming Y). Of course, you must know what triangle you''re "on top" of, which should be easy if the terrain is laid in a grid pattern.
A second way that I have used is using the plane equation of each terrain triangle. Then, given the X and Z of your object''s position, you can figure the Y from the plane equation.
If you want full physics, with gravity, and friction playing on your object, well, then it''s going to get a lot more complicated.
The NeHe Game Development forum on this website will have a lot more information about terrain following.
First, you need to calculate the height of the terrain below points at the front and back of your vehicle (the previous reply has suggested how this can be done). This will allow you to work out the angle that the vehicle needs to be rotated about a horizontal axis to be aligned with the terrain. The component of gravity in the direction that the vehicle is now pointing is given by g.sin(T), where g is the standard acceleration due to gravity and T is the angle between the vehicle in its new alignment and the horizontal.