Changing terrian through script

Hi,
I’ve looked through the documentation and still can’t work out a way that im able to change the heights of my terrain

I wan’t to be able to change the heights of certain ares in a terrain

can someone give me an example of how i can do this?

I’m trying to work out a way to use the diamond square algorithm on a terrain but first i just want to know how i can change the terrain

look at GetHeights and SetHeights.

GetHeights returns the height values in the range of [0.0f,1.0f]
SetHeights expect the height values in the range of [0.0f,1.0f]

The max height is defined by TerrainData.size.y, so if that is “512”, then the values of 0…1 from GetHeights will mean “0…512”.

Im still having touble sorry

What does get heights do? what makes it different to set heights?

and i don’t understand
“[0.0f,1.0f]”
i don’t get how that relates to what the documentation says sorry

SetHeights (xBase : int, yBase : int, heights : float[,]) : void

Sorry, this seems kind of basic - are you new to programming? If so, I recommend learning C#, it is an easy language to learn- maybe take a week or two to get the basics - and you will find everything much easier if you grasp the concepts.

But to answer your questions. GetHeights does what it says - it “gets” the height values in an array. The array contains values between 0 and 1.
SetHeights is the opposite - it sets the height values. The height values are between 0 and 1 inclusive.

Here’s a link where someone asked a similar question, and contains code:

sorry im learning java and am comming along however i still do not full understand this

GetHeight (x : int, y : int) : float

This give an array of the heights of x position and y position of the terrain. Why must the number values be less than one? Are the height values a percentage of the overall height of the map?
How do i use GetHeight?
float height = Terrain.activeTerrain.terrainData.GetHeight(0, 0); // so this essentailly gives me my height value of 0,0 in float (decimal?) form

Then SetHeights sets the height values. I have no idea how to use this though.
This is an example of how someone else used it:
Terrain.activeTerrain.terrainData.SetHeights(0,0,new[,]{{height + 0.001f}});

What is the new[,] for? and the curly brackets? it says that it increases the height value by 0.001 hence the height plus that (he had previously defined height by get height.

Sorry yet thanks this is probably really basic stuff but i can’t seem to understand it!

Yes, it’s percentage based, so to get a world position from a terrain you’d use terrain.GetHeights(x,y) * terrain.size.y.

That looks like some hilarious C# trickery.

new[,] : create a new two-dimensional array
{ : containing the following
{ : somehow having two of these causes each individual element of heights to be increased by 0.001f

thanks
although im still having trouble with set heights, is anyone able to give me an example how how i can use it in JS

[code/]
var desiredTerrainHeight = 10;

var height1 = Terrain.activeTerrain.TerrainData.GetHeights(0,0);

Terrain.activeTerrain.TerrainData.SetHeights(height1,10);

I set an array of my location
Then i change the height of that set location

my code is almost certainly wrong but can someone help?

anyone help? i really need it