Perlin Noise generating as vertical lines instead of noise.
I'm following a series of tutorials on YouTube about how to procedurally generate terrain using Perlin Noise. Everything was going fine until I made a change (I don't remember what I changed though) and the "noise" started to render as vertical lines. I've been trying to debug this for two days now, but I don't have any prior experience with Perlin Noise, and my googling and research haven't brought me anything. I don't know if I'm just not searching for the right thing but it would really help if someone could tell me what I'm doing wrong. Here's what the image looks like right now.
Here's the code for the noise generation script. using System; using System.Collections; using System.Collections.Generic; using UnityEngine;
public static class Noise {
public static float[,] GenerateNoiseMap(int mapWidth, int mapHeight, float scale, int octaves, float persistance, float lacunarity, int seed, Vector2 offset)
{
float[,] noiseMap = new float[mapWidth, mapHeight];
System.Random prng = new System.Random (seed);
Vector2[] octaveOffset = new Vector2[octaves];
for (int i = 0; i < octaves; i++) {
float offsetX = prng.Next(-50000, 50000) + offset.x;
float offsetY = prng.Next(-50000, 50000) + offset.y;
octaveOffset [i] = new Vector2 (offsetX, offsetY);
}
if (scale <= 0)
{
scale = 0.0001f;
}
float maxNoiseHeight = float.MinValue;
float minNoiseHeight = float.MaxValue;
float halfWidth = mapWidth / 2f;
float halfHeight = mapHeight / 2f;
for (int y = 0; y < mapHeight; y++) {
for (int x = 0; x < mapWidth; x++) {
float amplitude = 1;
float frequency = 1;
float noiseHeight = 0;
for (int i = 0; i < octaves; i++) {
float sampleX = (x - halfWidth) / scale * frequency + octaveOffset[i].x;
float sampleY = (x - halfHeight) / scale * frequency + octaveOffset[i].y;
float perlinValue = Mathf.PerlinNoise (sampleX, sampleY) * 2 - 1;
noiseHeight += perlinValue * amplitude;
amplitude *= persistance;
frequency *= lacunarity;
}
if (noiseHeight > maxNoiseHeight) {
maxNoiseHeight = noiseHeight;
} else if (noiseHeight < minNoiseHeight) {
minNoiseHeight = noiseHeight;
}
noiseMap [x,y] = noiseHeight;
}
}
for (int y = 0; y < mapHeight; y++) {
for (int x = 0; x < mapWidth; x++) {
noiseMap [x,y] = Mathf.InverseLerp(minNoiseHeight, maxNoiseHeight, noiseMap [x,y]);
}
}
return noiseMap;
}
}
Just let me know if you need any more information!
I didn't read the code but I know the offset for Y-axis are wrong.
Do you know what I should change? Sorry, I'm kind of new to this. The offsets are both set to 0, but I don't know if that's what you mean.
Answer by takochako987 · Jul 13, 2018 at 04:56 PM
Nevermind I found it myself. It was a stupid typo. I accidentally typed x - halfHeight
instead of y - halfHeight
.
Your answer
Follow this Question
Related Questions
Procedural Mesh Generation with Mathf.PerlinNoise Creates Flat, Irregular Terrain 0 Answers
How can I get a probability from perlin noise? 0 Answers
Seamless Perlin Noise problem. SOLVED 0 Answers
Mesh collider only working on part of procedurally generated mesh 1 Answer
Creating ridged perlin noise 0 Answers