Game Development Community

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:

%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?

#1
07/21/2008 (3:47 pm)
I found this to be a problem with my .mis file. I don't know what the problem was, but starting a new mission fixed it. I did compare all the terrain info from the "bad file" to a new file and could not see any difference. Even copy/pasting terrain infro from the new file over the bad file wouldn't fix it. At least I didn't spend a lot of time developing a level! I am still working on game code.
#2
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!