let an object follow a heightmap

How can I let an object follow a heightmap? The object have constant speed.

An easy way of doing it is moving it as usual along the X/Z-plane, and give it a Y-coordinate from the heightmap. Unless the heightmap has very steep hills, it’s a fairly acurate method.

For something to follow a heightmap smoothly, you need to interpolate the heightmap values.

Here’s some pseudo code:

Function GetInterpolatedHeight#( x#,z# )
ix=Floor(x) ;integer parts of x,z
iz=Floor(z)
fx#=x-ix ;fractional remainders
fz#=z-iz
y00#=GetHeight( ix,iz )
y10#=GetHeight( ix+1,iz )
y11#=GetHeight( ix+1,iz+1 )
y01#=GetHeight( ix,iz+1 )
ya#=(y10-y00)*fx+y00
yb#=(y11-y01)*fx+y01
y#=(yb-ya)*fz+ya
Return y
End Function