GetTerrainHeight always returns 0 - TGEA 1.7.0
by Nicolai Dutka · in Torque Game Engine · 07/19/2008 (4:14 pm) · 4 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:
And that will always give me the correct number for the Z position of the player. I need this to work properly so I can spawn enemies "i" distance from the player in any direction and have them NOT go through the terrain or get dropped from too high up.
Also note that %t will NOT always be equal to the player's transform, it may be set to any number of other game objects/elements.
So the problem again: Why does "getTerrainHeight(%x SPC %y);" always return 0 for me?
%t = $player.getTransform();
%x = getWord(%t,0);
%y = getWord(%t,1);
%z = getTerrainHeight(%x SPC %y);
echo("terrain height = "@ %z);The echo statement ALWAYS comes out 0 even though I can directly do this in console:
echo($player.getTransform());
And that will always give me the correct number for the Z position of the player. I need this to work properly so I can spawn enemies "i" distance from the player in any direction and have them NOT go through the terrain or get dropped from too high up.
Also note that %t will NOT always be equal to the player's transform, it may be set to any number of other game objects/elements.
So the problem again: Why does "getTerrainHeight(%x SPC %y);" always return 0 for me?
#2
I went back to my example games folder and loaded up one of them and tried and it returned the correct value for terrain height, so I am assuming the engine code is just fine as is....
07/21/2008 (12:39 pm)
I don't understand why I would need to touch the C++ code. I am using the T3D example folder fresh out of the box and have done nothing at all to any engine code. It is possible I deleted something in the mission file, but I wouldn't know what to look for...I went back to my example games folder and loaded up one of them and tried and it returned the correct value for terrain height, so I am assuming the engine code is just fine as is....
#3
So, I am comparing my mission file to the newMission.mis file and cannot see where the problem might be. Perhaps someone else can find the mistake? Here is my mission file (it's a test mission, so nice and small and I removed code for static shapes and the like to keep it smaller):
07/21/2008 (12:48 pm)
It is definitely the mission file. In the editor, I went to File->Open Mission and opened NewMission.mis, tried the code again, and got the correct value for getTerrainHeight.So, I am comparing my mission file to the newMission.mis file and cannot see where the problem might be. Perhaps someone else can find the mistake? Here is my mission file (it's a test mission, so nice and small and I removed code for static shapes and the like to keep it smaller):
//--- OBJECT WRITE BEGIN ---
new SimGroup(MissionGroup) {
canSaveDynamicFields = "1";
Enabled = "1";
cdTrack = "2";
CTF_scoreLimit = "5";
musicTrack = "lush";
new ScriptObject(MissionInfo) {
canSaveDynamicFields = "1";
Enabled = "1";
desc0 = "For Shader Testing.";
descLines = "2";
name = "Simple testbed";
};
new MissionArea(MissionAreaObject) {
canSaveDynamicFields = "1";
Enabled = "1";
Area = "-360 -648 720 1296";
flightCeiling = "300";
flightCeilingRange = "20";
};
new Sky(GlobalSky) {
canSaveDynamicFields = "1";
Enabled = "1";
position = "0 0 0";
rotation = "1 0 0 0";
scale = "1 1 1";
materialList = "scriptsAndAssets/data/skies/sky_skybox.dml";
cloudHeightPer[0] = "0.349971";
cloudHeightPer[1] = "0.3";
cloudHeightPer[2] = "0.199973";
cloudSpeed1 = "0.0005";
cloudSpeed2 = "0.001";
cloudSpeed3 = "0.0003";
visibleDistance = "4000";
fogDistance = "1000";
fogColor = "0.6 0.6 0.7 1";
fogStorm1 = "1";
fogStorm2 = "0";
fogStorm3 = "0";
fogVolume1 = "150 0 50";
fogVolume2 = "0 0 0";
fogVolume3 = "0 0 0";
windVelocity = "1 1 0";
SkySolidColor = "0.113 0.148 0.215 0";
useSkyTextures = "1";
renderBottomTexture = "0";
noRenderBans = "0";
renderBanOffsetHeight = "10";
skyGlow = "0";
skyGlowColor = "0 0 0 0";
fogVolumeColor1 = "1 1 1 1";
fogVolumeColor2 = "1 1 1 1";
fogVolumeColor3 = "0 0 0 1";
windEffectPrecipitation = "1";
};
new sgSun() {
canSaveDynamicFields = "1";
Enabled = "1";
azimuth = "0";
elevation = "35";
color = "1 1 0.8 1";
ambient = "0.4 0.4 0.5 1";
castsShadows = "1";
useBloom = "1";
useToneMapping = "1";
useDynamicRangeLighting = "1";
DRLHighDynamicRange = "1";
DRLTarget = "0.8";
DRLMax = "1";
DRLMin = "0.5";
DRLMultiplier = "1.4";
bloomCutOff = "1.5";
bloomAmount = "1.2";
bloomSeedAmount = "0.5";
direction = "0 0.954268 -0.298953";
position = "0 0 0";
rotation = "1 0 0 0";
scale = "1 1 1";
};
new SimGroup(PlayerDropPoints) {
canSaveDynamicFields = "1";
Enabled = "1";
new SpawnSphere() {
canSaveDynamicFields = "1";
Enabled = "1";
position = "500.703 715.858 100.01";
rotation = "0 0 1 0.570611";
scale = "0.940827 1.97505 1";
dataBlock = "SpawnSphereMarker";
Radius = "10";
sphereWeight = "1";
indoorWeight = "1";
outdoorWeight = "1";
homingCount = "0";
lockCount = "0";
};
};
new SimGroup(MegaTerrain) {
canSaveDynamicFields = "1";
Enabled = "1";
new TerrainBlock() {
canSaveDynamicFields = "1";
Enabled = "1";
position = "-2048 -2048 0";
rotation = "1 0 0 0";
scale = "1 1 1";
detailTexture = "scriptsAndAssets/data/terrains/details/detail1.png";
terrainFile = "scriptsAndAssets/data/missions/simple_multimap_0_09.ter";
squareSize = "8";
tile = "0";
detailDistance = "25";
detailScale = "256";
detailBrightness = "1";
texelsPerMeter = "8";
clipMapSizeLog2 = "9";
};
new TerrainBlock() {
canSaveDynamicFields = "1";
Enabled = "1";
position = "0 -2048 0";
rotation = "1 0 0 0";
scale = "1 1 1";
detailTexture = "scriptsAndAssets/data/terrains/details/detail1.png";
terrainFile = "scriptsAndAssets/data/missions/simple_multimap_1_09.ter";
squareSize = "8";
tile = "0";
detailDistance = "25";
detailScale = "256";
detailBrightness = "1";
texelsPerMeter = "8";
clipMapSizeLog2 = "9";
};
new TerrainBlock() {
canSaveDynamicFields = "1";
Enabled = "1";
position = "-2048 0 0";
rotation = "1 0 0 0";
scale = "1 1 1";
detailTexture = "scriptsAndAssets/data/terrains/details/detail1.png";
terrainFile = "scriptsAndAssets/data/missions/simple_multimap_0_19.ter";
squareSize = "8";
tile = "0";
detailDistance = "25";
detailScale = "256";
detailBrightness = "1";
texelsPerMeter = "8";
clipMapSizeLog2 = "9";
};
new TerrainBlock() {
canSaveDynamicFields = "1";
Enabled = "1";
position = "-0.0385742 -0.0022583 0";
rotation = "1 0 0 0";
scale = "1 1 1";
detailTexture = "scriptsAndAssets/data/terrains/details/detail1.png";
terrainFile = "scriptsAndAssets/data/missions/simple_multimap_1_19.ter";
squareSize = "8";
tile = "0";
detailDistance = "25";
detailScale = "256";
detailBrightness = "1";
texelsPerMeter = "8";
clipMapSizeLog2 = "9";
};
};
#4
07/22/2008 (12:37 pm)
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.
Associate Jaimi McEntire
King of Flapjacks
You may have more luck posting this in the TGEA section.