- Home /
Terrain GetHeights(0,0,Width,Height) different Results than GetHeight(x,y);
Why is this difference, and there are inaccuracies, when I use this:
When there should be a value shown(height on Terrain) the heightResult shows nothing, and when there is no height there is a value (low percentage that the result matches the GetHeight(x,y) method
heights[,] = TerrainData.GetHeights(0,0,TerrainWidth,TerrainHeight);
pos x = WorldCoordinates between 0 and Terrain Width(X Axis);
pos y = WorldCoordinates between 0 and Terrain Width(Z Axis);
float TempResult = heights[x,y] / 0.65535f * 100; // converted 16bit integer to float
float heightResult = TempResult * TerrainData.bounds.size.y; // Actual height Result
Unity provided GetHeight Method:
pos x = WorldCoordinates between 0 and Terrain Width (X Axis);
pos y = WorldCoordinates between 0 and Terrain Width (Z Axis);
float heightResult = TerrainData.GetHeight(x,y);
now if I compare the Results I can rely on Unity's GetMethod but as I think my Method should work aswell.
the Reason why I can't use Unity's getMethod is due to the Job System => I need to compare thousands of Positions in a single Call in the Editor. Maybe some one can explain why the two method's do not give the Same Results, have the Same Data at hand..
Answer by Bunny83 · Mar 12, 2019 at 01:56 PM
You have x and y reversed. See the documentation:
Returns a two dimensional array of heightmap samples. The samples are represented as float values ranging from 0 to 1. The array has the dimensions [height,width] and is indexed as [y,x].
why? why?? everything is in x,y,z thanks never woul have thought if that
@Bunny83 do you know why I need to multiply the Result float[,] by 600 to get the same Result?
Image data generally is laid out row by row. So the major index specifies the row, the $$anonymous$$or index the column. $$anonymous$$ultidimensional arrays are internally just flattend arrays and would have an index like [y * width + x]
As for the actual data, there are several different ways the heightmap data may be represented in memory. The GetHeights methods returns float values in the range of 0-1. I did not use the terrain engine very often. $$anonymous$$y guess would be that internally the heightmap data is actually in the 0-1 range and GetHeight multiplies the sample with the terrain resolution.
Your answer
![](https://koobas.hobune.stream/wayback/20220612193438im_/https://answers.unity.com/themes/thub/images/avi.jpg)