Hi all.
I am generating infinite tiles and am having trouble getting the PerlinNoise (height) to be applied to the world coords.The tiles repeat the same noise over and over.
Not getting x/z offsets…
The references I have gone over:
Catlike coding
Holistic3d
Sebastian Lague
The tiles are 50 x 50 – will always be increments of 10.
worldX & worldZ are the world coords of each tile.
noisePoints - number of vertices on one side (70 + 1)
float[,] CreateNoiseMapV2(int noisePoints, int worldX, int worldZ)
{
float[,] noiseMap = new float[noisePoints, noisePoints];
Vector2[] octaveOffset = new Vector2[terrainSettings.octaves];
System.Random prng = new System.Random(Statics.gameSeed);
float maxNoiseHeight = float.MinValue;
float minNoiseHeight = float.MaxValue;
float scale = ((float) terrainSettings.perlinScale <= 0) ? 0.0001f : (float) terrainSettings.perlinScale;
for (int i = 0; i < terrainSettings.octaves; i++)
{
float offsetX = prng.Next(-100000, 100000) + worldX;
float offsetY = prng.Next(-100000, 100000) - worldZ;
octaveOffset[i] = new Vector2(offsetX, offsetY);
}
for (int x = 0; x < noisePoints; x++)
{
for (int z = 0; z < noisePoints; z++)
{
float amplitude = 1f;
float frequency = 1f;
float noiseHeight = 0f;
for (int i = 0; i < terrainSettings.octaves; i++)
{
float sampleX = (x + octaveOffset[i].x) / scale * frequency;
float sampleZ = (z + octaveOffset[i].y) / scale * frequency;
float perlinValue = Mathf.PerlinNoise(sampleX, sampleZ);
noiseHeight += perlinValue * amplitude;
amplitude *= terrainSettings.persistence;
frequency *= terrainSettings.lacinarity;
}
maxNoiseHeight = (noiseHeight > maxNoiseHeight) ? noiseHeight : maxNoiseHeight;
minNoiseHeight = (noiseHeight < minNoiseHeight) ? noiseHeight : minNoiseHeight;
noiseMap[x, z] = noiseHeight;
}
}
// maxNoiseHeight -- To be used here
return noiseMap;
}