0

I'm developing a small project, which is a grid of 100 x 100 hexagons. In the script below, I paint my hexagons with the perlin noise, but the format I want to island does not go away. I'll leave my code and 2 examples as my map stays and how I wish it to stay.

My island

My Island

As i need

Im Need

int getColor(float x, float z)
{
    xTO = (int)x / terrainWidth - 30;
    zTO = (int)z / terrainHeight - 30;

    float v = Mathf.PerlinNoise((xTO + x + seed) * freq, (zTO + z) * freq);
    //  v += 0.001f;

    float form = formWorld(x, z);


    if (v < 0.25f)
    {
        //water
        return 0;
    }
    else if (v < 0.5f)
    {
        //sand
        return 1;
    }

    else if (v < 0.75f)
    {
        //grass
        return 2;
    }
    else
    {
        //Trees / Forest
        MakeNewTree(new Vector3(xx, 0, z * 7.5f));
        return 2;
    }
}
DROPE
  • 15
  • 7

1 Answers1

0

If you want your image to look more like the second one, the best option is going to be adding a circular gradient which offsets your Perlin Noise.

The easiest way to do this is to measure the distance from the center and combine that with the perlin noise.

Here's some untested code.

    int getColor(float x, float z)
    {
        xTO = (int)x / terrainWidth - 30;
        zTO = (int)z / terrainHeight - 30;

        float v = Mathf.PerlinNoise((xTO + x + seed) * freq, (zTO + z) * freq);
        //  v += 0.001f;
        v -= CircleOffset(x,z)/2; //Change the two to make the island bigger.

        float form = formWorld(x, z);


        if (v < 0.25f)
        {
            //water
            return 0;
        }
        else if (v < 0.5f)
        {
            //sand
            return 1;
        }

        else if (v < 0.75f)
        {
            //grass
            return 2;
        }
        else
        {
            //Trees / Forest
            MakeNewTree(new Vector3(xx, 0, z * 7.5f));
            return 2;
        }
    }

    float CircleOffset(float x, float y)
    {
        Vector2 center = new Vector2(terrainWidth/2,terrainHeight/2);
        float distance = Mathf.Sqrt((center.x - x)*(center.x - x) + (center.y - y) * (center.y - y));
        return distance/terrainWidth;
    }

Hope this helps!

Hexagon789
  • 315
  • 2
  • 4
  • 16
  • Unfortunately the result was not as expected, I left a link showing what happened. https://imgur.com/a/D5kzrnZ – DROPE May 26 '19 at 21:59