Most games take place on some sort of map, and the choice of map type has a fundamental impact on gameplay. But how to choose? For this terraforming game we know the map needs to span an entire planet. The most common method of doing this is to make the world flat and wrap around the east-west direction. But this is actually a cylinder. Now I don't know about you but the planet I live on is a sphere. You could wrap around north-south like we did with east-west but this turns the world into a torus (also not a sphere). As it turns out this is the same problem cartographers have been dealing with ever since they started making maps. In fact they even proved that it's impossible to do perfectly. At this point you need to ask does this matter? Most games decided that the advantages of a flat map outweighed these downsides. But for this game I think we need a spherical map.
Remember that the other map decision was to use a hexagonal grid. So we just need to cover the surface of a sphere with hexagons.
So map projections, there’s a lot of them, and they all do the same thing, and none are perfect… But why do I care? Well, this is a game about terraforming planets so there needs to be some way to show that planet to the player. In my first post you can see the initial version of this. The planet is displayed as a flat map so I need to use some projection. But this has problems, it distorts the amount of area at each latitude, you can’t go over the poles, and I think it looks bad. The answer to all of this is just make the planet spherical instead of flat, essentially use a globe.
So how to do that? Well, it turns out that if I want to keep the hex grid on the surface it’s
As it turns out that's impossible. Thankfully there is a simple way around this problem, just add 12 pentagons to our hexagons. This is called a Goldberg polyhedron. Now making it!
The first step is to construct an icosahedron. We do this by first defining the locations of all the vertices.
Then connect the vertices into faces. Each line defines a face using the indices of the vertices in the vertex list.
If we tell Unity to draw this we get a nice icosahedron.
Still needs work to become a sphere. So we subdivide each edge and make new faces:
Now there are more vertices but it’s still flat. To fix this we take the new vertices and push them out a bit:
That’s better, let’s subdivide it more:
So now we have a nice sphere, but as you've probably noticed there still aren't any hexagons. Well we’re not quite there yet. First we need to break down the sphere into smaller chunks. But why? Unity has a limit to the number of vertices in a mesh. We’re not hitting that yet but as we make the terrain more complicated we might. The easiest way is to use each of the original 20 faces of our icosahedron as a chunk. Giving each chunk a color gives us a nice a beach ball.
Now it's finally time for hexagons. Each vertex of the sphere gets replaced by a hexagon except the 12 original vertices. Those are our pentagons.
Now we finally have the basis for our map. We'll make it look more interesting next time.