0
\$\begingroup\$

My Terrain was looking a bit plain so to freshen it up a bit I decided to add mountains to the terrain generation. Unfortunately the Mountains don't look very natural with the surrounding terrain. mountains zoomed out
single mountain

I generate the mountains currently by:

1.start at a random spot on the map that is above sea level

2.raise that to the highest point and have surrounding blocks staircase up to it using a radial noise pattern

3.move a certain number of blocks away and repeat until the mountain reaches the coast

here is the code for extra clarification:

void generateMountains()
{
    //Find Starting Location
    int startingX = Random.Range(0, grid.columns);
    int startingY = Random.Range(0, grid.rows);
    RidgedMultifractal noise = new RidgedMultifractal();
    noise.Frequency = .01;
    noise.OctaveCount = 8;

    while (grid.FindTile(startingX, startingY).elevation < -3)
    {
        startingX = Random.Range(0, grid.columns);
        startingY = Random.Range(0, grid.rows);
    }
    //createMiddle highest point
    Grid.Tile middlePoint = grid.FindTile(startingX, startingY);

    //how many mountainBlocks to be generated
    while(middlePoint.elevation > SEALEVEL)
    {
        var tilesAroundMid = grid.getNeighborhood(middlePoint, false, 25);

        for (int i = 0; i < tilesAroundMid.Count; i++)
        {
            //setting the distance away from mid
            float distanceToCenter = Mathf.Sqrt(Mathf.Pow(middlePoint.x - tilesAroundMid[i].x, 2) + Mathf.Pow(middlePoint.y - tilesAroundMid[i].y, 2));

            if (tilesAroundMid[i].elevation + Mathf.RoundToInt(((float)noise.GetValue(tilesAroundMid[i].x, tilesAroundMid[i].y, .1) * 10 - distanceToCenter) + 15) >= tilesAroundMid[i].elevation)
            {
                tilesAroundMid[i].elevation += Mathf.RoundToInt(((float)noise.GetValue(tilesAroundMid[i].x, tilesAroundMid[i].y, .1) *10 - distanceToCenter) + 15);
            }
        }
        middlePoint = grid.FindTile(middlePoint.x + Random.Range(10,15), middlePoint.y + Random.Range(10,15));

    }


}

How would I change my code so that the mountains generated looks more natural and realistic with the surrounding terrain?

\$\endgroup\$
  • \$\begingroup\$ Check out Fractals. \$\endgroup\$ – Pieter Geerkens Mar 16 '15 at 2:51
  • 3
    \$\begingroup\$ or perlin noise \$\endgroup\$ – dnk drone.vs.drones Mar 16 '15 at 7:12
2
\$\begingroup\$

I wouldn't seperate the mountain generation from the general terrain generation but combine them.

Today the usual approach to generating landscapes is using 2D or 3D noise functions like perlin or simplex. By combining several amplitudes and octaves you can add both general height (like mountains and valleys) and some detail. You'll probably need to experiment with the values for the number of different noises and their octave/amplitude values to a natural looking result.

2D noise might be fine for you since you basically get a heightmap which seems like what you're going for. 3D noise has the added benefit of being able to generate overhangs and caves which probably won't work out great in your case which looks like only 16 height levels.

Another and simpler approach to creating a realistic heightmap is called diamond-square in which you basically start a small grid with only 4 random heights at the corner and interpolate the gaps (with some random deviation) in a row of two-step rounds.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

How are you making the differences in height on your more flat terrain? It looks like you've already got something along the lines of concentric rings going on so why not grab the center of one of the rings and push it up, push each ring around it up, and then radio noise between the smaller vertical distance of each ring?

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.