Some of you may have noticed my I get carried away when I’m bored" post, where I worked out the breadth first algorythm myself because I didn’t have access to the lectures…
Today, same boat… No videos
Well, I started wondering how all of the techniques we’ve learned so far would apply to Hexgonal tiles I knew the BFS algorythm would work on it (you just have to add the directions), but how to work out the grid, and the automatic placing and labelling…
The first step was creating the hexagons… Thanks to Unity giving us ProBuilder for free now, it didn’t take too long to work up a reasonable Hexagon (I created a cylinder with 6 sides in the pro builder… well, two of them, one for the top, and one for the rest of the body). That was the easy part. Next came some dramatic changes in the math…
You see, the factor on a hex grid isn’t the same as the factor on a cube… gridSize=10 won’t cut it. It turns out the x spacing and y spacing are quite different on a hex… And of course, your script needs to figure out if it’s an even column or an odd column…
Once I worked out the math, after SEVERAL false starts, I finally got Hex tiles moving and labelling themselves in the editor. Since I designed my program so that all the in game elements are descendents of “Gridtype”, simply checking the “Hexagonal” boolean was all it took to get everything to conform. (An enemy, actually using the same enemy as the regular grid) has no idea if it’s hex or not, it doesn’t care, that’s all handled by its base class Gridtype.). Same with the spawners.
So here’s my example of some enemies perusing my shiny new Hexagonal grid.