public virtual void SetHeights() { float[, ][,] combinedHeights = new float[terrainSegments, terrainSegments][, ]; //Initialize matrix of arrays for heightmaps for (int segmentX = 0; segmentX < combinedHeights.GetLength(0); segmentX++) { for (int segmentY = 0; segmentY < combinedHeights.GetLength(1); segmentY++) { float[,] heights = new float[heightResolution, heightResolution]; //Fill heightmap for segment for (int x = 0; x < heightResolution; x++) { for (int y = 0; y < heightResolution; y++) { //Get height positions and subtract segment iteration to align seams float heightX = x + (segmentX * heightResolution) - segmentX; float heightY = y + (segmentY * heightResolution) - segmentY; //Normalize to height resolution (0, 1) heightX /= heightResolution; heightY /= heightResolution; //heightY = (heightY - -1) / (1 - -1); //Normalize to (-1, 1) //heightY = (heightY - -1) / (1 - -1); //Normalize to (-1, 1) //Read in heights from heightmap heights[y, x] = (float)lastOutputModule.GetValue(heightX, heightY, 0) * heightStrength; //heights x and y value need to be swapped for terrain to line up (loop order issue?) } } combinedHeights[segmentX, segmentY] = heights; //Assign heights to segment } } Terrain.SetConnectivityDirty(); //Set Heights for (int x = 0; x < terrainSegments; x++) { for (int y = 0; y < terrainSegments; y++) { terrainDatas[x, y].SetHeights(0, 0, combinedHeights[x, y]); } } }