I’ve been playing around in Unity with procedural world generation for a while now, inspired by such great articles as; Red Blob Games’s: Polygonal Map Generation for Games, Martin O’Leary’s fantasy map generator and especially Experilous’s procudual planet generation.

My dream was to make a simple spherical map generator that I could use for rpg or strategy games. It should be build out of cells to represent areas on the map. From those cells I would create a mesh based on the terrain in those cells.

Now, I’ve tried to get Delaunay triangulation to work for ages… and I finally just gave up and decided to try a simpler solution.

Cells and Connections

I’d start with a icosahedron, and subdivide its surfaces for exponentially increasing the number of cells.

I want each Cell to know its neighbours to help me with pathfinding later on. Since each Cell is a triangle of equal size I can iteratively go through my list of Cells and find which ones share vertexes.

If two cells share the same two vertexes; then they are neighbours and I give each cell a reference to the other.

Now to be clear. THIS IS A TERRIBLE WAY OF DOING IT.… but it’s the only way I know how to do it… yet!

The reason that this is an awful way of keeping track of how the cells are interconnected is that for the process takes an awful amount of time. Comparing all the cells is fine for 20, 80 and even for 320 cells… but the larger the cell count the more it grinds everything to a halt.

On the plus side, it did make for some snazzy visuals when I made it go through Unity’s Update function:

Using the Update function means that the process is even slower. But I get to have visual feedback while it’s working and don’t just have to cross my fingers and hope for the best.

This means about 20 minutes worth of work for my laptop at 4 subdivisions and makes it give up completely at 5.

Needles to say, this is unacceptable. So I found a way to make the problem irrelevant for now. Binary Files!

Instead of generating new worlds with new cells and new connections, I’d make them once.. And then save their data as binary files for later use. Now I can load the data each time I need it… the problem is still there, but now it’s not making me feel so bad anymore.

Anyway, let’s put some continents on this sphere!

Tectonic plates

I’ve tried to use perlin noise for heightmaps a number of times in different projects, but the resulting landmasses always end up looking wrong to me. So I tried to emulate Andy Gainey’s method of generating the topology from the simulated interaction of moving tectonic plates… (why do I keep doing this to myself?)

First I generate a number of plates on the sphere. Each plate gets a starting height, a cell to originate from, a direction and a rotational value (relative to the surface normals of the starting cell) From there I use my cells interconnectedness to grow each plate until the world is covered.

Now I let each cell inherit the height of their tectonic plate as well as give it a vector based on the plates directional speed and rotation.

I won’t go much into how i did the last, as it involved my old enemy.. Math!

Basically I had find the rotational momentum for each cell based on its location in relation to its plate’s point of origin, then I add the base momentum from the plate.

Now every cell contains a vector and we can (again) iterate through all the cells and compare their directions to find the way the plates interact.

Real plate tectonics is a lot more complicated than my approach which boiled down to;

Moving towards one another? Up the elevation. Moving away? Down elevation.

This creates a series of trenches and mountain ranges that are a bit on the extreme side. But if we iterate through another few times to smooth out the elevation, the result starts to get near what I want.

Still a lot of things to do, next up will be sea level, temperature and proper biomes.

Thank you for taking the time to read my ramblings.