- Home /
Perlin Noise Implementation
This may sound like a noob question, but I have been looking for a solution for a few days now. I have written a randomized map generator (it generates a map in real time). I need to be able to give each point a y value (otherwise it is flat). So, here is my question; how do I generate a perlin noise heightmap, and get the height of one pixel at a time?
var SomeSortOfPerlinNoise = Perlin noise (x_var in for loop, y_var in for loop);
vertices[value_on] = Vector3(x_var, SomeSortOfPerlinNoise, 0.0f),y_var);
I just need set the value of SomeSortOfPerlinNoise, and my map generator will work. Any suggestions?
Answer by Cherno · Jan 25, 2015 at 05:49 PM
Unity has built-in Perlin Noise support: Mathf.PerlinNoise.
for(x = 0; x <worldSizeX; x++) {
for(z = 0; z < worldSizeZ; z++) {
float height;
height = Mathf.PerlinNoise(x, z) * 10f;
}
}
It's still not working. It is still generating a flat terrain. (Just to clarify, I've got something working, so I know it's not the generator. I just want to use perlin noise, as it is what I want the map to look like).
$$anonymous$$aybe the scale is too big? Try to follow the documentation, it includes a scale multiplier.
It's not the scale, as when I *100, it still is the same, but higher up.
I tried Random.Range(1,3)
just to make sure the generator works (not the effect I'm looking for, but helpful for debugging), and it generated at different heights. So it's something to do with Perlin Noise, and not the scale, ect.
$$anonymous$$aybe you could post your code again which implements the Perlin Noise, and we can see what needs to be changed.
Have you tried inserting a Debug.Log line to check the values generated by the Perlin.Noise function?
Answer by malkere · Feb 02, 2015 at 09:17 AM
Your scale is not too low it's too high. PerlinNoise doesn't use big numbers it works in low numbers... from what I can tell.
I had the same problem today and diving by 10 made it extra jagged. dividing by 1000 made it a big slow wave. Still not what I'm looking for, but the answer is PerlinNoise, you and I just don't fully understand it ;p
That helped me a lot with making a 2D top-down level with random spots of caves, gold and $$anonymous$$erals.
http://studentgamedev.blogspot.no/2013/09/unity-voxel-tutorial-part-3-perlin.html
ya that's a great tutorial for voxels. I used his method in my $$anonymous$$ing too.
Your answer
Follow this Question
Related Questions
improve generate tilemap with perlin noise 1 Answer
Adding rivers to procedural generated 2D map 1 Answer
Always same result from Mathf.PerlinNoise() 2 Answers
Perlin noise problem 0 Answers
2d Top-Down Perlin noise map using Mathf.PerlinNoise 3 Answers