I’ve been trying to make a sort of randomized terrain for a while, and I’m unable to write a perlin noise function myself, partly due to laziness and partly to being a total noob.
So I borrowed the Mathf.PerlinNoise function. The documentation says that you give it the two coordinates, and it gives you a random number on a texture with the same coordinates or something.
But when I printed a bunch of Mathf.PerlinNoises, with different hand-typed values, all of them printed the same number : 0.4652731. So can anyone explain this to me?
EDIT:
Here’s my script:
function Start () {
print(Mathf.PerlinNoise(0, 0));
print(Mathf.PerlinNoise(2, 0));
print(Mathf.PerlinNoise(0, 5));
print(Mathf.PerlinNoise(10, 3));
print(Mathf.PerlinNoise(2, 0));
print(Mathf.PerlinNoise(1, 1));
}
Here’s the results (one of them):
0.4652731
UnityEngine.MonoBehaviour:print(Object)
PerlinHeight:Start() (at Assets/PerlinHeight.js:5)
Whole numbers will return the same result; use fractions.
Mathf.PerlinNoise work with smaller values marked as float.
Like:
Debug.Log(Mathf.PerlinNoise(0 / 100f, 0 / 100f));
Debug.Log(Mathf.PerlinNoise(2 / 100f, 0 / 100f));
Debug.Log(Mathf.PerlinNoise(0 / 100f, 5 / 100f));
Debug.Log(Mathf.PerlinNoise(10 / 100f, 3 / 100f));
Debug.Log(Mathf.PerlinNoise(2 / 100f, 0 / 100f));
Debug.Log(Mathf.PerlinNoise(1 / 100f, 1 / 100f));
Think of PerlinNoise() as producing value in a random terrain. That is adjacent values are not random, but instead will produce similar values (perhaps a bit more, or perhaps a bit less) as if you are walking some hilly countryside. I find that when working with Perlin noise I have to get the range of values right. Here is a answer with a script for creating a hilly plane. It should be straight forward to modify it for use in a Terrain.
http://answers.unity3d.com/questions/417793/perlin-noise-plane-manipulation.html
I’ve never used it, but from the documentation, it appears that given x and y coordinates, the algorithm will return a value between 0.0 and 1.0. Different coordinates should give different values.