- Home /
How to make multiple terrains match together?
I'm working on a procedural terrain generation using a Simplex noise algorithm and placing 9 tiles(terrains) in a 3x3 square. The problem is that the terrains aren't matching together like in the image:
And this is the code which generates the heights for every tile:
private void GenerateHeights (int tileZ, int tileX)
{
if (tiles [tileZ, tileX] == null)
return;
Terrain tempTerrain = tiles [tileZ, tileX].terrainTile;
int width = tempTerrain.terrainData.heightmapWidth;
int height = tempTerrain.terrainData.heightmapHeight;
float xRatio = frequency / (float)width;
float zRatio = frequency / (float)height;
float[,] heights = new float[height, width];
for (int z = 0; z < height; z++) {
for (int x = 0; x < width; x++) {
float noiseX = (x + tempTerrain.transform.position.x) * xRatio;
float noiseZ = (z + tempTerrain.transform.position.z) * zRatio;
heights [z, x] = noiseGenerator.Noise (noiseX, noiseZ) * detailScale;
}
}
tempTerrain.terrainData.SetHeights (0, 0, Normalize (heights));
}
If i comment this function i get 9 perfectly aligned square plane tiles so the initial alignement is correct... I found this script (stitchscape) which i think i could solve my problem but it is not free in the asset store
I forgot to mention that i already call the SetNeighbors function for every tile and this improves a little the result but it's not enough
Answer by getyour411 · Jan 04, 2015 at 06:36 AM
Buy Stitchscape
Thanks but i would like a solution more "DIY", maybe finding the error in the code because the tiles don't mismatch too much so it is not completely wrong.
agreed, it has something to do with the way you are accessing the noise.
The edge of one terrain needs to read the same data as the matching seam of the next terrain. For this, modify the step :
float xRatio = frequency / (float)(width - 1);
float zRatio = frequency / (float)(height - 1);
untested. I'm not sure this if this is exactly where the step needs to be modified, but that's the theory.
Ok thanks I got better results following your hints but it's still not matching... I need to find how much and where subtract to make them match
Answer by vbs · Sep 10, 2017 at 09:10 PM
For your width and height you should use heightmapResolution values. Here's another similar question: http://answers.unity3d.com/questions/966290/aligning-simplex-noise-generated-terrain.html
Your answer
Follow this Question
Related Questions
How to generate a grid for procedurally generated platforms 1 Answer
Procedurally generating terrain? 0 Answers
QuadPlane to Sphere Terrain Generator Misaligned 1 Answer
A* Procedural Terrain 1 Answer