Index out of range exeption error help
I,m trying to make a map using perlin values and random generation. but for some reason my octaves Offset can only be set to one to not get a index out of range error. After searching around. both in the code and online, I have been unable to understand where this error comes from, so can anyone help me explain it?
Pressing the error takes me to the following line of code, so I'm asuming the error stems from there somehow. octaveOffsets [i] = new Vector2(offsetX, offsetY);
The rest of the script looks like this: public static class Noise { public static float[,] GenerateNoiseMap(int mapWidth, int mapHeight, int seed, float scale, int octaves, float persistance, float lacunarity, Vector2 offset) { float[,] noiseMap = new float[mapWidth, mapHeight]; System.Random prng = new System.Random(seed); Vector2[] octaveOffsets = new Vector2[octaves]; for (int i = 0; 1 < octaves; i++) { float offsetX = prng.Next(-100000, 100000) + offset.x; float offsetY = prng.Next(-100000, 100000) + offset.y; octaveOffsets [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 = ((float)x - halfWidth) / (mapWidth*scale) * frequency + octaveOffsets[i].x * frequency; float sampleY = ((float)y - halfHeight) / (mapHeight*scale) * frequency + octaveOffsets[i].y * frequency; 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; } }