- Home /
Terrain Clamping
Hello.
So, after some experimetning I managed to get a script generating a fairly simple terrain with serveral perlin noise layers. Here's the script:
using UnityEngine;
using System.Collections;
public class TerrainGenerator : MonoBehaviour {
public Terrain terr;
private float frequency;
private float amplitude;
private int Warstwy = 20;
public NoiseLayer[] noiseLayers;
void Start () {
terr.heightmapMaximumLOD = 0;
noiseLayers = new NoiseLayer[Warstwy];
float frequency = .008f;
float amplitude = 0.085f;
for( int n=0; n<noiseLayers.Length; ++n)
{
noiseLayers[n] = new NoiseLayer();
noiseLayers[n].frequency = frequency;
noiseLayers[n].amplitude = amplitude;
amplitude *= 0.5f;
frequency *= 2f;
}
int xRes = terr.terrainData.heightmapWidth ;
int zRes = terr.terrainData.heightmapHeight ;
float [,] heights = new float[ xRes, zRes];
for(int z = 0; z < zRes; z++){
for(int x = 0; x < xRes; x++){
float height = 0;
foreach(NoiseLayer noiseLayer in noiseLayers)
{
float f = noiseLayer.frequency;
float a = noiseLayer.amplitude;
height += Mathf.PerlinNoise(x*f, z*f) * a;
}
heights[x,z] = height;
}
}
terr.terrainData.SetHeights(0,0,heights);
}
}
}
And here's a typical result:
Now, I have several questions. First, how can I get a clamp height effect shown in this video?
http://www.youtube.com/watch?v=mXTxQko-JH0
Second: The terrain looks fine, but is there a way to have somethin like biomes? Like, in one area there would be for example mountains, in another hills and they would all blend together nicely. I heard something about Voronoi diagram, but i don't know how to implement it in my code/use it.
Thanks in advance for all the answers.
-Xentarok
P.S: If you have any questions aks them in the comments.
P.S.2: English isn't my native language so I apologize for any mistakes.
Your answer
![](https://koobas.hobune.stream/wayback/20220613130802im_/https://answers.unity.com/themes/thub/images/avi.jpg)