Help with improving perlin noise function!
So, I'm really noob with scripting in unity. For my game (minecraft type) I'm generating terrain by instantiating blocks in a 1000x1000 grid; I then change their height values with this function which uses Mathf.PerlinNoise. It tries to get the arguments between 0 to 1, so they can be put in perlin noise function:
public float calcNoise(float x, float y) {
float d_count = Mathf.Floor(Mathf.Log10(x) + 1);
if(d_count == 1) {
x = x/10.0f;
y = y/10.0f;
}
else if (d_count == 2) {
x = x/100.0f;
y = y/100.0f;
}
else if(d_count == 3) {
x = x/1000.0f;
x = y/1000.0f;
}
else if(d_count == 4) {
x = x/10000.0f;
y = y/10000.0f;
}
else {
x = x / 2.0f;
y = y / 2.0f;
x = x / 10000.0f;
y = y / 10000.0f;
}
if(1.0f - x <= 1.0f && 1.0f - y <= 1.0f)
{
return Mathf.PerlinNoise(x, y);
}
else
{
x = x / 2.0f;
y = y / 2.0f;
return Mathf.PerlinNoise(x, y);
}
}
I feed the function with the x, y coords of the block in grid. For example, Fifth block in the 11th row will go like this - calcNoise(11, 5). While there are some hills but there are several areas which are out right flat. They don't even look realistic like some of the examples i've seen on the net. Is there a better way to get nice valleys and mountains with perlin noise?
Anyone? I still cant get it to work, half of my terrain is flat :/