GetTerrainHeight does not seem consistent
by Wesley Hopson · in Torque Game Engine · 02/27/2007 (11:52 pm) · 2 replies
I was playing around with the getTerrainHeight function because it seemed like a better way of getting the height of the terrain than a ray cast aimed down which is what i was doing until i realised torque already had a function to find the height of the terrain. Anyway I noticed I was not getting consistent values when compared to the players Transform So I did a little test.
Echo("Player Height = " @ getword($PlayerId.getTransform(), 2));
%temp = getwords($PlayerID.getTransform(), 0, 1);
Echo("Terrain Height = " @ getTerrainHeight(%temp));
Echo("Difference = " @ getword($PlayerId.getTransform(), 2) - getTerrainHeight(%temp));
Using that code and walking around and sampling i got this back from the console
Player Height = 186.519
Terrain Height = 186.505
Difference = 0.0139951
Player Height = 186.543
Terrain Height = 186.527
Difference = 0.0164192
Player Height = 186.578
Terrain Height = 186.572
Difference = 0.00581067
Player Height = 186.64
Terrain Height = 186.634
Difference = 0.00569214
Player Height = 186.979
Terrain Height = 186.871
Difference = 0.108074
Player Height = 189.759
Terrain Height = 189.538
Difference = 0.220792
Player Height = 194.813
Terrain Height = 194.434
Difference = 0.379223
Player Height = 196.663
Terrain Height = 196.435
Difference = 0.227575
Player Height = 200.601
Terrain Height = 200.229
Difference = 0.372362
Player Height = 202.96
Terrain Height = 202.765
Difference = 0.195229
Player Height = 206.032
Terrain Height = 205.817
Difference = 0.21535
Player Height = 206.805
Terrain Height = 206.617
Difference = 0.187858
Player Height = 201.406
Terrain Height = 201.262
Difference = 0.143686
Player Height = 198.933
Terrain Height = 198.881
Difference = 0.051927
Player Height = 195.164
Terrain Height = 195.043
Difference = 0.121275
Is their any reason why this seems so inconsistent the player is on top of the terrain right so I thought the height returned by the function would at least be proportional. But this seems almost random in how it varies.
Also which is more process intensive GetTerrainHeight or A rayCast
Echo("Player Height = " @ getword($PlayerId.getTransform(), 2));
%temp = getwords($PlayerID.getTransform(), 0, 1);
Echo("Terrain Height = " @ getTerrainHeight(%temp));
Echo("Difference = " @ getword($PlayerId.getTransform(), 2) - getTerrainHeight(%temp));
Using that code and walking around and sampling i got this back from the console
Player Height = 186.519
Terrain Height = 186.505
Difference = 0.0139951
Player Height = 186.543
Terrain Height = 186.527
Difference = 0.0164192
Player Height = 186.578
Terrain Height = 186.572
Difference = 0.00581067
Player Height = 186.64
Terrain Height = 186.634
Difference = 0.00569214
Player Height = 186.979
Terrain Height = 186.871
Difference = 0.108074
Player Height = 189.759
Terrain Height = 189.538
Difference = 0.220792
Player Height = 194.813
Terrain Height = 194.434
Difference = 0.379223
Player Height = 196.663
Terrain Height = 196.435
Difference = 0.227575
Player Height = 200.601
Terrain Height = 200.229
Difference = 0.372362
Player Height = 202.96
Terrain Height = 202.765
Difference = 0.195229
Player Height = 206.032
Terrain Height = 205.817
Difference = 0.21535
Player Height = 206.805
Terrain Height = 206.617
Difference = 0.187858
Player Height = 201.406
Terrain Height = 201.262
Difference = 0.143686
Player Height = 198.933
Terrain Height = 198.881
Difference = 0.051927
Player Height = 195.164
Terrain Height = 195.043
Difference = 0.121275
Is their any reason why this seems so inconsistent the player is on top of the terrain right so I thought the height returned by the function would at least be proportional. But this seems almost random in how it varies.
Also which is more process intensive GetTerrainHeight or A rayCast
About the author
#2
02/28/2007 (9:43 am)
Hmm that makes since I did notice that the difference seemed to be greater when i was on the side of a hill than when I was only reasonably flat terrain. Well I did another test to compare a raycast aimed down versus the getTerrain height and they do return the exact the same values so I guess it is no different than what I have been using. Now my only question left is which is more taxing to the system. At the moment I am guessing it is probably the ray cast since why have a specialized get terrain height function if a simple ray cast could give you the same results.
Torque Owner Stefan Lundmark
Should you want to test this further, make a terrain with flat steps at different heights and check the height difference at different steps. It should be close to the same on all steps.