Terrain Following

I have been working on a simple OpenGL game that uses very simple terrain. I had height mapped terrain but dropped it in favour of a simpler retro look. The game will be a simple racing game, similar to the classic “Stunts”, the terrain will be similar. My problem is how do I get the car to follow the terrain? It should be simple but the solution eludes me. I have a 2 dimenional map which contains tile numbers, zero would be flat terrain, 1 would be the flat top of a hill, 2 would be the hill side (ramp) etc… each tile is a 3D tile of course, the hilltop tile is a simple quad, presently the vertices for it are:

{-6.0f, 0.0f, 6.0f}
{ 6.0f, 0.0f, 6.0f}
{ 6.0f, 0.0f,-6.0f}
{-6.0f, 0.0f,-6.0f}

… the hilltop tile is the same except the height (Y) is all 3.0f rather than 0.0f. The ramp tiles are similar with two of the Y co-ordinates set to 3.0f and two set to 0.0f, except for corner tiles which are made up of two triangles, one for the flat section, the other for a ramp. Anyhow, I think you get the idea… I am pretty sure I will have to re-organize my data. Any ideas on how to do terrain following so that a car follows the terrain, properly goes up a hill side (rather than through it! heh). Below is a screenshot looking down a road at the hillside.

Can you give the pseudocode of how you are currently moving the car in order to see why it is going through the ramp? I’m not sure I can answer but that would help clarify the problem to me.

Thanks.

The trick is to remember that you are dealing with a real 3D world. What you need to do is make sure that the car follows the 3D terrain. There are coordinates for the position of the terran so just use them for the car as well.
For example, given that the car is at (x,y), determine the correct z based upon your terrain map.

Thanks for the replies. I currently don’t have any type of terrain following at all. I simply move the camera around, changing the X and Z but not the Y. I manually adjust Y if I want to change my height to look at something but it doesn’t follow the height of the map.

I did manage to successfull do some terrain following with a height map. The problem is I am not using a height map with this game. The map is a two dimensional array of integers represent different 3D tiles. If you have ever played the game “STUNTS” (or 4D Driving by Mindscape) you will know what I am trying to do. Each tile is a 3D object, part of the terrain. All the tiles are square, some flat low terrain, some high hilltops, some like ramps for the sides of hills. Now following the terrain on the flat surfaces is a no brainer. The car simply moves along the X and Z co-ordinates (not X & Y by the way, remember, this is opengl) and the height (Y) is going to be either low (zero) or on a hilltop (currently a height of +6). What I am having a problem with, is if I am on a 3D tile that is part of the hillside, where it isn’t flat… it is like this / sloped, how do I properly follow that slope? I know it has to do with getting a normal of that plane, but I don’t know much about getting normals. Is there a formula I need to know? Given the tile’s four vertex’s (each corner) and the car is somewhere in between, I should be able to figure out the normal for that tile (not really a problem I guess) but how do I get the height for the car itself and the angle it needs to be on based on it’s position within that tile?

I could do a height map for this, but it really isn’t the way I want to go with this particular game, it would only complicate things more than I want.

Below is a wireframe image of the terrain to illustrate what I am doing. #1 and #2 are the tiles I have problems figuring out the angle of the car and the height the car will be (Y) while on that tile. The other flat tiles (#3 and #4) are easy of course.

[This message has been edited by Night Hacker (edited 03-19-2004).]

I am not familiar with the game you mentioned so I am not entirely sure I understand your approach. It sounds, though, that perhaps you may have to incorporate some trig into the car’s movement over the ramps (?) But then, that would probably also require a height map.

Sorry, don’t think I can be much help here.

Given the X,Y, and Z coordinate of a rectangle, you can compute the Y based on any X and Z within the rectangle by using a 2D interpolation technique. Do a search on 2D linear interpolation.