RTS terrain using Libnoise for Unity

Hello.

So, about a month ago I started working on a RTS game in Unity, something like Civ 5 combined with Europa Universalis IV. The first thing I started working on was a random terrain generator. I experimented a litle with Mathf.Perlin, but then i found the Libnoise library, which was just perfect for my needs. So after some work, i got this:

And this code:

using UnityEngine;
using LibNoise.Unity;
using LibNoise.Unity.Generator;
using LibNoise.Unity.Operator;
using System.IO;
using System;
using System.Collections;

public class TerrainGenerator : MonoBehaviour {

	public Terrain terr;
	
	void Start(){

		float frequency = 0.006f;

		float amplitude = 0.01f;

		int xRes = terr.terrainData.heightmapWidth ;
		int zRes = terr.terrainData.heightmapHeight ;

		float [,] heights = new float[ xRes, zRes];

		Perlin perlin = new Perlin();
		RiggedMultifractal rigged = new RiggedMultifractal();
		Billow bill = new Billow();
		Voronoi voro = new Voronoi();

		Noise2D noisemap = new Noise2D(xRes,zRes, perlin);

		//Continents---

		for(double z = 25; z < zRes - 25; z++){
			
			for(double x = 25; x < xRes - 25; x++){

				double height = 0d;

				height += noisemap.Generator.GetValue(x * frequency, 0d,z*frequency ) * amplitude; 

				heights[(int)x,(int)z] = (float)height;

			}
			
		}

		terr.terrainData.SetHeights(0,0,heights);

		//--------

		//Mountains---

		float frequency2 = 0.021f;
		
		float amplitude2 = 0.017f;

		Noise2D noisemap2 = new Noise2D(xRes,zRes,perlin);

		float [,] heights2 = new float[ xRes, zRes];

		for(double z = 0; z < zRes; z++){
			
			for(double x = 0; x < xRes; x++){
				
				double height = 0d;

				if(terr.terrainData.GetHeight((int)x,(int)z) > 1f){  

					height += 0.02f + noisemap2.Generator.GetValue(x * frequency2 , 0d,z* frequency2 ) * amplitude2; 
				
				}

				heights2[(int)x,(int)z] = (float)height;
				
			}
			
		}
		
		terr.terrainData.SetHeights(0,0,heights2);

		//--------*/

		//Mountains2------


		float frequency3 = 0.0115f;
		
		float amplitude3 = 0.019f;
		
		Noise2D noisemap3 = new Noise2D(xRes,zRes,rigged);
		
		float [,] heights3 = new float[ xRes, zRes];
		
		for(double z = 0; z < zRes; z++){
			
			for(double x = 0; x < xRes; x++){
				
				double height = 0d;
				
				if(terr.terrainData.GetHeight((int)x,(int)z) > 0.1f){  
					
					height += 0.02f + noisemap3.Generator.GetValue(x * frequency3 , 0d,z* frequency3 ) * amplitude3; 
					
				}
				
				heights3[(int)x,(int)z] = (float)height;
				
			}
			
		}
		
		terr.terrainData.SetHeights(0,0,heights3);

		//-----------*/

		
	}

}

Now, as you can see, I’m still struggling with some problems, so I decided to share them here (not in unity answers because this is a bit lenghty question, and I also want to have a discussion going on).

1. How can I have the continents not touching the edges of the terrain? I made a simple border, but it looks very unnatural.
2.How can I get more realistic mountains? I mean, right now they are generated using the RiggedMultifractal Noise, but they don’t look like real Mountain ranges.
3.Because the Rigged noise is generating some 0 values, i have to add a little bit to it, so the continenst will be visible, but it creates these nasty cliffs, and I don’t know how to get rid of them.

4. And finally, I don’t really know if Unity Terrain is good for my purpose, maybe I should use mesh?

So, these are my questions, if you know an anserw to any of them I’d be more than thankfull if you wrote it here!

So again, thank in advance for any anserws.

-Xentarok

P.S: English isn’t my native language, so I apologize for any mistakes.

For smooth borders, I would first choose a distance to check from the borders. So say you want to start lowering the terrain the closer you get to the border. And let’s say you want to start lowering within 50 meters of the border.
So for every height value you set in the terrain:

Get distance from border.
If distance <= falloff distance (50 meters), then
falloff amount = distance/50
actual terrain height = terrain height * falloff amount

This way, far away from the border the terrain will be higher, but if it is within 50 meters, the closer the terrain is to the border the lower it will be.

That help?

Oh, and as far as using Unity’s terrain vs a mesh…depends on the features of the terrain that you want. The Unity terrain is pretty good out of the box, but if you want holes/caves in your terrain, or a vast terrain it may be painful.

That definetly solved one problem, thanks!