jeudi 31 janvier 2019

C# unity generator world hexagon

everything fine ?

Well, right now I'm creating a simple little world generator in hexagons. It works fine, but it has some problems. I would like to create it a bit more together, it makes very large corridors and leaves several holes in the world.

I will leave here my code and an image of what is happening.

MAP IMG

In addition to being very separate, the passages are very narrow.

MAP IMG

//------------------------------------------------------------------------//

public GameObject[] hexTransform;
public List<Vector3> createdHex;



IEnumerator GenerateWorld()
{

    for (int i = 0; i < ammountHex; i++)
    {
        int pos = Random.Range(0, 5);
        int textureMap = Random.Range(0, hexTransform.Length);

        PositionHex(pos);
        SpawnHex(textureMap);
    }

    //      surface.BuildNavMesh();

    yield return 0;
}

//Set Position of hex

private void PositionHex(int pos)
    {
        switch (pos)
        {
            case 0:
                //Cima
                transform.position = new Vector3(transform.position.x - (offsetSize / 2), 0, transform.position.z + 0.75f * offsetSize);
                break;
            case 1:
                //Esquerda
                transform.position = new Vector3(transform.position.x + offsetSize, 0, transform.position.z);
                break;
            case 2:
                //Direta
                transform.position = new Vector3(transform.position.x - offsetSize, 0, transform.position.z);
                break;

            case 3:
                //Baixo
                transform.position = new Vector3(transform.position.x + (offsetSize / 2), 0, transform.position.z - 0.75f * offsetSize);
                break;

        }

    }

//And Finish Spawn Hex

void SpawnHex(int pos)
        {
            if (!createdHex.Contains(transform.position))
            {
                GameObject Hex = Instantiate(hexTransform[pos], transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;
                createdHex.Add(Hex.transform.position);
                Hex.name = "Hex" + transform.position.x + " / " + transform.position.z;

    }
}




Aucun commentaire:

Enregistrer un commentaire