Hello
when i import the terrain by code, how high should I raise the height until it becomes reality?
Hi,
Your question is rather unspecific and hard to understand. What do you mean by “import terrain by code”, and what do you mean “how high should I raise the height until it becomes reality?” what do you mean by “reality” in this case?
How much should this parameter be so that the height of the terrain is equal to the height in reality?
What’s the “height in reality”?
According to the manual, this parameter is:
So it depends on what your heightmap looks like. Let’s say you have a 100 meters tall mountain, exported from another tool as a height map such that 1 (pure white) represents 100 meters tall, and 0 (pure black) represents 0 meters tall.
In Unity, you will need to set Terrain Height to “100” so that it matches your original mountain.
Now, if you export the height map such that 0.5 (gray) represents 100 meters tall, you have to set Unity’s Terrain Height to 200, so that 0.5*200 = 100.
thanks so much , how can change this parameter by code?
The y component of TerrainData.heightmapScale:
https://docs.unity3d.com/ScriptReference/TerrainData-heightmapScale.html
It says it can’t assign to it, it’s read only
Makes sense, since changing that once the terrain has been generated would involve re-creating the entire terrain surface which sounds very costly.
What are you trying to do?
I want to change the height of terrain at the runtime
Is there no way?!
Even if I generate the terrain at the runtime or any other way, can’t I build it with the desired height?!
no this is in default height range
Not sure what you mean. The height range in the terrain depends on the contents of your height map and the size of your terrain. So it’s whatever you want it to be.
Something like this would create a terrain that’s 50 meters high in places where the height map has a value of 1:
var data = new TerrainData();
data.size = new Vector3(100,100,50); // create a terrain that's 100 meters wide, 100 meters long and 50 meters high.
data.heightmapResolution = 512;
data.SetHeights(...): // set the height map
Terrain.CreateTerrainGameObject(data);
That’s what I wanted, thank you