I am generating Heightmaps using Perlin Noise and a simple method found on the Scrawk blog in his “Simple Terrain Generation” article, I have changed the main body of the code however but are using a modified version of his heightmap generation:
public void SetHeight(float[,] htmap){
float ratio = (float)TMS.TerrainSize/(float)HMS.HeightMapSize;
for(int x = 0; x < HMS.HeightMapSize; x++){
for(int z = 0; z < HMS.HeightMapSize; z++){
float X = (x+1*(HMS.HeightMapSize-1))*ratio;
float Z = (z+1*(HMS.HeightMapSize-1))*ratio;
float Hills = Mathf.Max(0.0f, MountnNoise.FractalNoise2D(X, Z, 6, TMS.MountnFrequency, 0.8f));
float Flatland = GroundNoise.FractalNoise2D(X, Z, 4, TMS.GroundFrequency, 0.1f) + 0.1f;
htmap[z,x] = Flatland+Hills;
}
}
}
The main issue I am running into is, that with each loop through in the main body it calls the “SetHeight(HTMP)” function which reproduces the same heightmap for each of my tiles, the original method created one huge heightmap that was stretched across every tile, which meant each tile lined up perfectly because the heightmap was also “chunked” into sections much like the terrain tiles.
As You can see from the above image, the Heightmap is repeated rather than a different heightmap being generated each time the loop goes around. I have no need for my terrain to be repeated, nor the heightmap to be spread accross all terrains because I want to achieve different height areas which will then be different “biomes” as such.
Is there a simple way to ensure the loop that calls the “SetHeight” function is reset to create a new heightmap for each terrain tile?