Terrrain: GetHeights array inverted..???

I just have to ask this before going slowly insane:
Is the resulting array from a call to TerrainData.GetHeighs() inverted. Ie. the format of the float array is [z,x]*and not [x,z]*as expected?

When placing things based on the array, everything is mirrored UNLESS I reverse the index order, then everything lines up. Would anyone care to share some insight into the (poorly documented) coordinate formats of the terraindata arrays?

Many thanks in advance!

Maybe it just uses right-handed axis instead of left-handed axis? When writing GUI code, some APIs have (0,0) coordinate on top left corner, and some have it on bottom left corner. And even if that’s not the case here, why is the arrangement in that array an issue? Also there is always TerrainData.GetHeight(int x, int y) method to simplify reading height data.

In scene coordinates, it does seem to be using (0,0) as the “bottom left” corner, i.e… positive values climb up the respective x,z axises as expected. This is logical. However the resulting array from a call to GetHeights seems to be inverted. Check this:

A call to GetHeights(x,z) returns an array that is of the dimensions [z,x]:

width = 15, depth = 2 in the above code will log:
“2 15” in the console.

Is it me being stupid because it is friday or is the implementation backwards?

1 Like

I guess it’s just backwards. Too lazy to check, but I remember from some time ago having similar confusion about terrain data array organization :slight_smile:

Yes, confirmed it is indeed “backwards”. Thanks for the sanity check - I was sure I was doing something wrong.

Anyway, it is a bit poor that this is not documented and does not follow normal convention or the format used to call for data. If you are expected to feed an x,z point to GetHeights to get the data, you would expect the returning array to be in the same ordering… :slight_smile:

1 Like