All posts

Procedural Terrain Generation in GTA San Andreas

I was looking for something I made a long time ago, and ended up down memory lane instead. As a kid I played a lot of Grand Theft Auto: San Andreas, and especially San Andreas Multiplayer, the unofficial multiplayer mod. That mod is where I learned to code in several languages, and where I picked up a lot about Linux, websites, certificates, servers and more.

The countryside in GTA San Andreas. In multiplayer it was even emptier: the mod removed a lot of vegetation, because it wasn't synced between players and could cause problems.

I spent a big part of my childhood in this game. My guess is over 10,000 hours, coding for it and playing it. I still think back to it sometimes: the friends I made, the projects, and everything I learned.

I loved the game, but the countryside never felt rural enough to me. I wanted thicker forests and more to explore. And after more than ten years on the same map, I knew every corner of it. There was nothing left to discover.

One of my last projects was a roleplay server. Players created a character and built a life in the game. They could join any organisation (government, legal or illegal), get a job, buy houses, businesses and vehicles, make friends and even start a virtual family.

I wanted a world you could really interact with: collect materials, learn skills and craft items, like in 7 Days to Die, another game I enjoyed. That’s what got me thinking about a procedural terrain generator.

The first problem was the existing map, which was already full of trees, plants, rocks and so on. Luckily there was a function called RemoveBuildingForPlayer that can remove parts of the map. Set the position to 0, 0, 0 and the range to 6000, and an object is gone from the entire map.

A generated bitmap where each colour is a biome, some fixed and some generated. Every dot on this map is also an object placed in the game.

Next, I generated a layout of biomes across the map. Some biomes had to be hardcoded because of how the terrain in the game is shaped. The rest were generated with noise algorithms, so they’d look varied and natural. Based on that layout, I placed objects that fit each biome in a grid across the map. In the end the system generated over 200,000 objects: forests, deserts and other kinds of landscape.

That’s a lot for such an old game, which was only built to handle a few thousand extra objects at most. To get around that limit I used a streamer. It only keeps the objects near the player loaded and unloads them again when the player moves away. That way I could have that huge number of objects without the game falling over.

I never finished covering the whole map, but I think it would have ended up at around a million objects. My lack of 3D modelling experience was another problem. I managed to edit one object in-game, but it wasn’t great, and making my own models was beyond me back then. If I could have added my own objects instead of only using the game’s default ones, the project would have felt a lot more alive.

Here are some of the videos I’ve been able to dig up from the project: