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 *= 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*.x;_
_ float sampleY = (x - halfHeight) / scale * frequency + octaveOffset.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!