PDA

View Full Version : let an object follow a heightmap



12-02-2001, 04:11 AM
How can I let an object follow a heightmap? The object have constant speed.

Bob
12-02-2001, 04:23 AM
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.

Si
12-03-2001, 11:54 AM
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