Terrain get sample height gives slightly wrong results,Terrain sampleheight gives SLIGHTLY wrong answer
I want the terrain height. I have been forced to use raycasts but would like to get useful output from the terrain heightmap. Can anyone tell me why I get slightly wrong/ inaccurate heights?
here is some of the code. It finds the right terrain chunk and converts coordinates to world and tries to take a height like this;
returnHeight = terrainObjects[indexOfHeightSearchTerrain].GetComponent().SampleHeight(new Vector3(worldSpaceX, 0, worldSpaceZ));,Terrain sampleheight returns slightly wrong value, my code correctly selects the relevant terrain chunk and asks for heights at a world position. I am but don't want to use raycasts.
//float worldSpaceX = (X scaleFactor) + terrainCoordsOfPt.x worldSpaceterrainChunkWidth; //float worldSpaceZ = (Z scaleFactor) + terrainCoordsOfPt.y worldSpaceterrainChunkWidth;
////for (int i=0; i< terrainObjects.Length; i++)
////{
//// if (CoordinatesOfChunk[i] == terrainCoordsOfPt)
//// {
//// indexOfCurrentTerrain = i;
//// }
////}
//returnHeight = terrainObjects[indexOfHeightSearchTerrain].GetComponent<Terrain>().SampleHeight(new Vector3(worldSpaceX, 0, worldSpaceZ));
Answer by Menyus777 · Dec 14, 2017 at 04:44 PM
Maybe my friend its because you dont need to convert your poisition into absolute positions :), just use Myterrain.SampleHeight(MyGameObject.trasnform.postions); What you are looking for is Terraindata.getheights();