Not logged in, Join Here! or Log In Below:  
News Articles Search    

 Home / Game Design & Programming / How to move unit smoothly on terrain? Account Manager
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.

January 19, 2005, 06:40 AM

i am a beginner for game programming. now i am doing my degree thesis and my subject is "path finding on 3D Terrian". i am facing problem about moving the unit on the terrain along the found path......

can someone give any suggestion about the algorithm or trick to move the unit smoothly....??the library that i used is openGL and VC++ is using. thanx


January 19, 2005, 08:19 AM

You already have found the path and stored the tiles that your object has to move over?

In that case, it's just keeping track of the current and next tile in that track. When your object arrives at a tile, it checks what's the next tile in the track and starts heading that way in smooth steps, until it has arrived. Then the process repeats itself until you're at the end of the track.


January 19, 2005, 09:06 AM

If you are talking about the unit following the height of the terrain, do what CaptainP suggests, and interpolate the height from the height of the corners of the tile.

Just Google on "terrain following" and you should find what you need.


January 19, 2005, 09:44 AM

I take that back - i just tried various Google searches on this subject and couldn't find ANYTHING!

A good topic for a FlipCode article, I'd say....


Rui Martins

January 19, 2005, 11:00 AM

Well, the trick is always "interpolate".

to stricktly follow the terrain, you just have to project or intersect the path (you already have) with the polys edges it crosses, this will give you a sequence of points which you should use to interpolate your move.

Since you mentioned smooth, I have to mention that this follow the polys EXACTLY. if you want to smooth this movement, you can approximate the next path track (next two points) using at least 3 points and interpolate a function that passes over them.
The interpolation method you use is up to you, there are many out there. The most smooth/continuous would be a NURB or BSPLINE (simplification of NURB) fitted using the already mentioned points.

Note however that by smoothing, you will force some interpenetration of the moving object with the terrain.


January 19, 2005, 12:07 PM


This thread contains 6 messages.
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.