We are just beginning work on this game, and we're using the Unity engine. We chose Unity for its availability, ease-of-use, and wide variety of deployment platforms.
This week's post will mostly be about hexagons.
What's so great about hexagons? Well, as the logo at the top of the page may suggest they are a pretty significant part of a lot of tabletop and wargames. They provide a more accurate and natural way of moving game pieces around than a square grid. However, they are a little trickier to draw than a grid of squares.
Unity measures the position of game entities with a three-dimensional vector. Our game board will mostly be flat, so we can ignore the height dimension for now. That leaves us to consider position on a two-dimensional plane, like a cartesian co-ordinate plane.
Remember math class? |
But how do you draw a grid of hexagons?
Well, it might help to imagine them as a grid of squares where every second column (or row, depending on your perspective) is offset a little.
Notice how each tile has 6 neighbours touching it. |
Seeing as a hexagon grid is analogous to a square grid with offset rows, it may be tempting to try to number it like a square grid. Depending on how this is done, the results may not be helpful.
If you try to keep the axes at 90 degrees to each other, you may end up with something like this.
x-axis in red, y-axis in blue |
axes as above |
Now, to implement this in Unity, I followed the approach described here. As a programmer, I am much more comfortable with creating and modifying game objects from scripts rather than using Unity's drag and drop features. I won't go into detail here, but I first created a HexManager script, which spawns new game objects and attaches the HexModel script to them. Ideally, I would like to create a prefab out of the hexagon objects, as the game board will likely be the same in every level, but this is a useful construct and will do for now.
So, we have a way of drawing hexagons where we want them, and a logical way of describing where that is. Next week, we will be working on adding some interactivity to this video game, getting something to happen when you click on these hexagons.
In addition the article linked above, I also found 'Hexagon grid: Generating the Grid' and 'Hexagon grids: coordinate systems and distance calculations' to be of the greatest help.
No comments:
Post a Comment