1
\$\begingroup\$

I am trying to generate terrain using perlin noise however the terrain being generated is a plateau. Here is the code that I'm using:

var xlength = 65.0;
var ylength = 65.0;
var scale = 4.1f;
var heights = new float[xlength, ylength];
function Start () {
    for (var i = 0; i < xlength; i++)
        for (var j = 0; j < ylength;j++)
            heights[i,j] = Mathf.PerlinNoise(Time.time * i / xlength * scale/1000,Time.time * j / ylength * scale/1000)*i*j;
    gameObject.GetComponent(Terrain).terrainData.SetHeights(0,0,heights);
} 

What am I doing wrong here?

\$\endgroup\$
1
\$\begingroup\$

If you want seamless 'chunks', then you should evenly sample between whole integers.

 heights[i,j] = Mathf.PerlinNoise(i / xlength, j / ylength);

And resulting data must be between 0..1 (so don't scale it here).

heights: Array of heightmap samples to set (values range from 0 to 1, array indexed as [y,x]). - Unity Documentation: TerrainData.SetHeights

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.