Hello guys, im trying to apply realtime terrain deformation based on the players position.
i found out you can do this by using TerrainData.SetHeightsDelayLOD, As the Reference tells
public void SetHeightsDelayLOD(int xBase, int yBase, float[,] heights);
xBase = int pixels of the x position in Hightmap
yBase = int pixels of the y position in Hightmap
heights = Float [int,int] each int represent how many pixels of the area around xbase and ybase its gonna get deformed. But the script reference tells us, heights = Array of heightmap samples to set (values range from 0 to 1, array indexed as [y,x]). You can’t set anything between 0 and 1 since its an integer and as i said above its in pixels instead and its just the area around the xbase and ybase, so theres no possible way to set actual height is it? is that a bug?
But to clarify heights, look in your Terrain object in the inspector, look under the gear (Terrain Settings) and find the “Terrain Height:” entry.
“Terrain Height” is what the values in Heights[,] are scaled to, from 0.0f to 1.0f, scaled up to the “Terrain Height” value in local vertical terrain space.
If you want some sample operating code to transact against the Unity TerrainData heightmap stuff, you can check out my MakeGeo repository. It has a terrain ramp cutter, and a “make terrain from perlin noise” area too.
The terrain height is 15 from the inspector, in code if you try to new float[0.2f,0.5f] for example you get “Cannot implicitly convert type ‘float’ to ‘int’. An explicit conversion exists (are you missing a cast?)”
You’re cross-conflating two unrelated ideas here: the notion of what is actually stored inside a single entry (or cell) in a float[,] array (which is a two-dimensional array), and how you index it, which is by two integer coordinates supplied inside of square brackets, the across and the down if you will.
Think of the heightmap like a spreadsheet: each cell has a floating point number in it. Each cell is indexed by a column number and a row number.
The floating point number from 0 to 1 inside each cell will tell you from 0 to TerrainHeight how high that area of the ground is.