GetTerrainHeight always returns 0 - TGEA 1.7.0
by Nicolai Dutka · in Torque Game Engine Advanced · 07/21/2008 (12:28 pm) · 3 replies
I am trying to spawn some items and creatures but am having trouble with the terrain height. I narrowed down the code to this:
The echo statement ALWAYS comes out 0 even though I can directly do this in console:
echo($xform);
And that will always give me the correct number for the Z position.
So why does my echo statement always return a zero value?
%t = $xform
%x = getWord(%t,0) + getRandom(-3,3);
%y = getWord(%t,1) + getRandom(-3,3);
%z = getTerrainHeight(%x,%y);
echo("Terrain height for enemy spawn location is: "@ %z);The echo statement ALWAYS comes out 0 even though I can directly do this in console:
echo($xform);
And that will always give me the correct number for the Z position.
So why does my echo statement always return a zero value?
#2
It's because you are using a MegaTerrain. getTerrainHeight is expecting a single terrain block named "terrain". That is a problem that has been (knock on wood) fixed with TGEA 1.71. You can now do getTerrainHeight at any point, as well you can use getTerrainHeightBelowPosition which will take a 3D point and return the terrain height, which is useful if you just want to pass an objects position right to the function and not worry about any (admittedly high) height limits.
07/22/2008 (12:46 pm)
I'm going to copy/paste my response from your original thread as this is probably the more appropriate place for it:It's because you are using a MegaTerrain. getTerrainHeight is expecting a single terrain block named "terrain". That is a problem that has been (knock on wood) fixed with TGEA 1.71. You can now do getTerrainHeight at any point, as well you can use getTerrainHeightBelowPosition which will take a 3D point and return the terrain height, which is useful if you just want to pass an objects position right to the function and not worry about any (admittedly high) height limits.
#3
07/22/2008 (4:29 pm)
Woot! Thanks a bunch!
Torque 3D Owner Nicolai Dutka