- Home /
Always same result from Mathf.PerlinNoise()
Hi,
I'm having some trouble using the Perlin Noise generator.
using UnityEngine;
using System.Collections;
public class PerlinTest : MonoBehaviour {
private float inNum;
// Use this for initialization
void Start () {
inNum = 0.0f;
}
// Update is called once per frame
void Update () {
Debug.Log(inNum + ": " + Mathf.PerlinNoise(inNum,0.0f));
inNum = inNum + 100.0f;
}
}
I keep getting the same number. What am I doing wrong? Thanks!
I looked at that and, as far as I can tell, I'm using it in the same way. But I'm probably missing something. I was hoping a second (or third, fourth, or fifth) pair of eyes could help me spot what's wrong.
I was having this same problem with same results with this: public int groundPerlinNoise (int x, int z){ float noise = $$anonymous$$athf.PerlinNoise(x/ground$$anonymous$$aturity, z/ground$$anonymous$$aturity); noise*=groundVarience; noise+=groundHeight; return (int)noise; } I changed the type "int" to "float" for the args, like this: public int groundPerlinNoise (float x, float z){ float noise = $$anonymous$$athf.PerlinNoise(x/ground$$anonymous$$aturity, z/ground$$anonymous$$aturity); noise*=groundVarience; noise+=groundHeight; return (int)noise; }
Answer by robertbu · May 25, 2013 at 02:21 AM
Change line 15 to the following:
inNum = inNum + 0.01f;
I ran into this problem the first time I used PerlinNoise(). It appears that the results are mod 1.0. So you will have this issue if you use 1.0 or 100.0. But change the numbers to 1.01 or 100.1 and you will not longer get a repeating number. But such large numbers will not give you the smooth transitions either.
Just a minor correction, it's not mod 1 (which would imply the noise repeats every unit), but rather the returned value is the baseline value (theoretically it should be the median value, but that's not quite the case with Unity Perlin, at least not in my case as I detail in https://answers.unity.com/questions/1904122/unity-perlin-noise-value-distributiondistribution.html
if anyone reading this could test it for themselves that would be great, there should be an update where I found out this value to be 0.4652731) at integer coordinates. This isn't specific for Unity but is common to all Perlin noise implementations.
Also changing the number you add to inNum every update will change the scale (or in this case speed) of the noise, smaller increment means slower change.
Answer by JohnDoe20001 · May 17, 2016 at 01:00 PM
The Perlin Noise is getting value starting at the same point each time. The function is a string of the wave based values. So you are going to end up traversing the same landscape every time.
So you need to seed the function to force it to start ad different point.
using UnityEngine;
using System.Collections;
public class PerlinTest : MonoBehaviour {
private float inNum;
private int seed = (int)Network.time * 10;
// Use this for initialization
void Start () {
inNum = 0.0f;
}
// Update is called once per frame
void Update () {
Debug.Log(inNum + ": " + Mathf.PerlinNoise(inNum + seed,0.0f));
inNum = inNum + 100.0f;
}
}
Your answer
Follow this Question
Related Questions
3D Perlin Noise mesh even in all axes 1 Answer
Unity Perlin Noise Bug? 3 Answers
How to use Perlin Noise for waves 0 Answers
Perlin noise problem 0 Answers
Basics of Perlin Noise? 1 Answer