Update 1 – Grid generation

Once I decided I wanted to make a hexagon grid game I decided that I needed to make something that can generate a flexible hexagon grid for me. So, I began working out how I should generate this grid.

The first bit I did was to work out how far apart the tiles should be to form the grid. I did this by simply placing the tiles in the editor to work out how close they should be. Once I established how far away the tiles must be from each other, I then worked out how I would spawn the first 6 tiles. I did this by using the centre tile and then adding the difference to the position of each 6 tiles that surround the centre tile.

Here is how it generates the first section of the grid: https://gyazo.com/eedd3fa60585b524a40a10afce9c2e7c

Once I had accurately generated the first layer of the grid, I then looked at expanding the grid. I did this by expanding upon the first layer by creating tiles in a line from the six tiles that surround the centre. This created a web shape grid.

See the web shaped grid here: https://gyazo.com/f2cf323dc9f6ae6cd1889ce8d325f09e

Once I had this web shaped grid, I then had to fill in the holes around the grid. I did this by working out how much space is between the two closest tiles in the layer (that are already spawned). I then worked out how many tiles should go there and then instantiated tiles into correct positions to fill these gaps.

Finally, this is the grid generation algorithm working to generate a full hexagon grid: https://gyazo.com/3baf3283c157a2c30ae818999f1e2d50

Here is a screenshot of the final grid:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s