Home Unity

Unity Hex Map Generation

Offline / Send Message

I have a question about generating hex maps, specifically a way to implement a 3D map with a hex overlay. The closest example I can find that is used in a game is from the title "For the King." For background, I am inexperienced as a programmer and looking for input from someone with more experienced eyes. To me, it looks like the map is procedurally generated, possibly a different script for each biome and a script to put them all together. Then a hex grid is overlaid to guide pathfinding.

I am interested in learning more about two aspects of this map. The first: What is happening from a Unity/scripting perspective to generate this map. Second: what resources can I use to learn more about this style of hex map making.

I'm familiar with Cat-like Coding tutorials on the hex map subject, but to my inexperienced perception, this is a different way to generate a hex map, separate from what I am trying to learn.

I also understand, based on the depth some scripts can take, that this information may not be enough to understand what I'm trying to learn, feel free to probe with questions and help develop this amateur programmer.

I appreciate anyone willing to lend some advice or point me in the right direction to learn more about this type of map making and procedural generation. Thank you for your time and help!


  • poopipe
    Offline / Send Message
    poopipe grand marshal polycounter
    2d vs 3d is usually unimportant with this stuff - you can mostly use 2d techniques for navigation and layout - you just layer them up to get the third dimension.  

    hex tiling is pretty closely related to isometric tiling in terms of implementation so that might help you find tutorial examples . 
    The main difference in terms of generating the grid is the height:wdth ratio- it's sqrt(3)/2:1 for hex tiles and (i think) tan(45 degrees):1 for true isometric tiling (not necessarily what you'll see in video games). Both have an offset of 0.5*cell width for alternate rows.  

    Start with generating a square grid using modulo to break it into rows/columns. 
    there's a simple example here
    once you have that you just need to offset alternate rows (easy if you're using modulo) and adjust the row height (again, easy) 

    You can completely separate the grid generation and procedural generation parts of the equation  - the procgen part is essentially going to boil down to generating a global noise field that you sample at each cell center to determine which cell type to use - you can then apply any connection logic you need to tidy up edges etc.

    In terms of gameplay the hex tiling is a bit more complicated since you have three horizontal axes for movement to consider.
    I found this after a quick google - the interesting part in this respect starts at about 3 minutes 
     - not saying it's a great tutorial but it's the right subject matter. 

    I should point out that I generally avoid unity so can't really go into specifics. 

Sign In or Register to comment.