HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Getting terrain height

05-17-2007, 06:37 PM#1
zen87
Well just wondering... how to get terrain heigh ? currently im using a stupid method of getting a unit's real height

Collapse JASS:
function GetUnitZ takes unit u returns real
    return (GetLocationZ(GetUnitLoc(u))+GetUnitFlyHeight(u))
endfunction

any other simple native ?
05-17-2007, 06:51 PM#2
blu_da_noob
There is no other way to get terrain height. And that leaks a location.
05-17-2007, 07:00 PM#3
zen87
yes yes i know... was lazy to type out the full leakless code... anyway here's my full function of GetUnitZ, seriously there is no other easier way ? I hate using locations for some lame reason

Collapse JASS:
function GetUnitZ takes unit u returns real
 local location l = GetUnitLoc(u)
 local real z = (GetLocationZ(l)+GetUnitFlyHeight(u))
    call RemoveLocation(l)
 return z
endfunction
05-17-2007, 07:02 PM#4
blu_da_noob
No one likes using locations for it, but there is currently no other option. And just a warning, that function of yours won't return an accurate Z height for flying units. There is a smoothing factor built into the height system which will screw it up. And you will also want to null that location.
05-17-2007, 07:04 PM#5
grim001
It would also be faster if you moved a global location to X and Y of the unit instead of creating a new location; creating new handles is slow.
05-17-2007, 07:17 PM#6
zen87
Quote:
Originally Posted by blu_da_noob
No one likes using locations for it, but there is currently no other option. And just a warning, that function of yours won't return an accurate Z height for flying units. There is a smoothing factor built into the height system which will screw it up. And you will also want to null that location.
well at the very least we could get a value that very close to the actual height of the unit =\

grim001 : oh yeah !! thanks for reminding me that, kay now shouden't have any problem now!
Collapse JASS:
globals
    private location L = Location(0,0)
endglobals

private function GetUnitZ takes unit u returns real
    call MoveLocation(L,GetUnitX(u),GetUnitY(u))
 return GetLocationZ(L)+GetUnitFlyHeight(u)
endfunction