I’m planning to use Unity to do a computer port of a hex-based board game and would love any pointers/comments on my plan of attack that anyone would care to give.
My basic plan was to treat the gameworld internally in terms of hex numbers (the numbers are in XXYY format, where XX is the row and YY is the column) with elevation. So the “coordinates” of a unit would be something like “0513+4” to mark that it’s in the 5th row, 13th column, 4 levels above the plane of the map.
Various functions would let me feed in pairs of coordinates to get distances in terms of hexes, bearings, etc. That way the game logic can be kept in nice pure hex terms and match the original game as closely as possible. Then when it comes to actually dispaying the units on the map, I’d convert the hex coordinates to true X,Y,Z coordinates.
This seems like the most straightforward approach to me, but I fear I’m missing something crucial or making my life too difficult. I’d greatly appreciate any critiques before I go coding myself into a corner!
I don’t think you’re missing much at all. I was thinking just this AM (in the shower as a matter of fact) how easy it’d be to create a hex-based board game (I was thinking about a game like Memoir 44).
Use z-index to indicate height as you said. Movement is even easier … you know the exact distance between the centres of two hexes in all six directions from you current position so it’d be easy to “snap” a unit’s movement to that. Even rotating is a breeze … fixed 60 degree increments.
Camera set to ortho view and you’re set.
I know someone else will be along soon to give more pointers but I think it’s a fabulous idea and easily done.
For the map screen of my game (which isn’t hex based, but that doesn’t really matter), I gave every map cell a script which has references for each of the neighbouring cells. Since wiring up the neighbour references would have been very boring to do manually, I wrote an editor script to do it for me. This script also lays out the cells in the desired arrangement in the first place.
The benefit of going to these lengths is that you can use the references between cells as a means of detecting valid paths that your units can travel along. It’s a lot easier at runtime to just look at the list of exits from a given cell than it is to start looking for objects based upon their coordinates in space.
That’s an awesome idea! In this case the map’s in space with no terrain or line-of-sight issues. I can see that being a big help for land maps with terrain and other features.
Oh thank goodness. I was envisioning a game that consists of finding the hidden egg in an image file with a hex-editor. I am very glad to see that’s not the case…
Dear god no. That sounds like one of the classes I took in college though… Fun class, but it’d probably make a lousy game.
Although I have been pondering a game to teach the concepts behind assembly langauge that would use both six-sided polygons for the map and base-16 numbers…