With the idea of (re)creating a strategy game on a hexagonal grid in 3D, I set out to implement my own solution for a 3D (hexagonal) tilemap system. After some experimentation with GL and trying to exploit Unity's 2D tilemap system, I realised that a preview package existed that did exactly the task I wanted to achieve: place Game Objects on a tilemap (see GameObject Brush in the package's documentation).
Yet apparently this solution only works for square grids (I haven't tried rectangular grids) - painting hexagonal tiles resulted in this:
So I ended up modyfing the script for the GameObject Brush, with the result being what I called "HexBrush" - it allows me to paint landscapes like this:
which actually fit the grid. Even more excitingly, we can actually change the z-position of tiles to create 3D landscapes:
One might be inclined to say "But if you increase the z-position too much, there will be holes in the map..." - which is absolutely true and looks like this:
Does this mean this project is doomed? No.
Quite some blood, sweat and tears later I am proud to present you this:
There is two reasons I am particularly proud of this:
The result of Unity's combine functionality is the mesh on the left-hand side (for simplicity a single tile is shown), while all we need is the result of the custom algorithm (right-hand side mesh).
Look again at the two pictures above to see how filling holes introduces additional triangles!
Then I added some simple particle effects and a script to rotate the sails of wind mills and the wheels of water mills. It's amazing how much nicer things look already with just a little effort :)
This is nice and all, but something important is missing! Maybe you noticed the humanoid model in above image? Let's have this guy walk around!
Soon after Dijkstra's algorithm and A*-pathfininding are implemented and our guy can follow the shortest path between two vertices (you can try this yourself in the demo: just click on two different tiles; if not already standing on the first tile, the model will be placed onto it automatically).
At this point I want to highlight these awesome tutorials on pathfinding and hexagonal grids and thank Amit Patel for sharing this amazing content!
Note that pathfinding in the demo has some quirks (which aren't particularly hard to fix, it just is not a high priority for me right now).
Also you might have noticed that the mouse highlight in the demo does not work properly on tiles containing rivers, the simple reasons behind that being the structure of the underlying mesh and my vertex extraction not working on it. Not yet!