- Home /
Best practices for interactive hexagon map?
I am planning to build an open-world game building on hexagon maps. The player is supposed to start out with only seven visible hexes but can expand the field in any direction. Each hexagon is supposed to be able to change its appearance (i.e. texture and maybe even height). Also, the user is supposed to interact with the individual tiles (reacting to touch events / via Raycast method).
What are the best practices for this?
The two options I (as quite a Unity newbie) consider up to now are:
Individual hexagon game objects (or hexagon prisms), spawned at runtime, or
A procedurally generated plane with triangles to form a hexagon structure
While option 1) is arguably easier to implement (though, I manually need to place the hexagons) I am afraid I may run into performance problems once the map reaches a certain size. Sizes of well over 1000 tiles are to be expected. For option 2) I am not yet quite sure wether it is feasible to individually change the appearance of each triangle/hexagon on the plane and how the map can be expanded during gameplay (starting with 7 hexagons, growing in all directions).
Can someone point me to useful resources? And what's the best option in your opinion – or is there even a better way? I know there are quite a few frameworks in the asset store for Hex Grids – but I'd like to stick to free resources for now.
Thanks – and I'm glad for every hint!
Nicolas
Resources I found up to now:
Procedural Hexagon Grid Framework, 50$ on asset store: http://u3d.as/bn3
Primitive Plus, a free add-on in the asset store which, among others, adds Hexagon / Hexagon prism game objects: http://u3d.as/akb
A great youtube tutorial how to make procedural planes: https://www.youtube.com/watch?v=bpB4BApnKhM&list=PLbghT7MmckI4qGA0Wm_TZS8LVrqS47I9R
An awesome article about Hexagons: http://www.redblobgames.com/grids/hexagons/
Answer by Cherno · Mar 31, 2015 at 11:32 AM
Definitely go with runtime mesh generation. Hex tiles are quite complicated because of the math involved for finding out if a point is inside one hex or the other. I wrote my own terrain hex engine for a BattleTech-like game and it drove me nearly insane! As for textures, traditional splat map shaders won't do you much good because they can only support up to five or six different textures max, not enough for a wide variety of terrain styles. I haven't been able to find a shader that copies the Unity Terrain shader with it's unlimited textures. So, you are left with creating submeshes and multiple materials for each chunk, possibly using vertex blending to get smooth borders between different textured tiles.
Here are some links I bookmarked for the project:
link text link text link text link text link text link text link text link text link text
These are from my project:
Hi, thanks for your detailed and nicely illustrated answer. With runtime mesh generation you mean the approach number 1) where each hexagon is an individual mesh generated at runtime? Thank you again :)
Each mesh is not an individual mesh. A mesh can have up to ~65k vertices, so the area is divided into chunks, each chunk being one gameobject and thus one mesh. That also means that each chunk is made of multiple hex tiles, with each one having at least six vertices.
I should also add that the mesh doesn't have to be generated at runtime; The neccessary functions can also be called in edit mode with an editor extension. This is something I only attempted in my latest project unrelated to hex tiles but related to mesh generation, of course.