Infinite procedurally generated world

Example scene which demonstrates how to make a graph follow the player around in an infinite world.

Contents

Graph setup

This example uses a smallish grid graph which follows the player around. In an infinite world, one cannot generate the whole graph at once, so instead we only generate a graph around the player and then move it as the player moves.

We ensure that the graph has enough resolution to represent the obstacles in the world, and that it is large enough to cover a decent sized area around the player. A smaller graph would result in less overhead as it moves, but then player would not be able to plan paths around large obstacles.

See

You can read more about this in the tutorial Large worlds.

Note

When testing how well the scene performs, make sure that you hide the graph visualization, as updating the graph visualization can be much slower than updating the graph itself.

Procedural world generation

The ProceduralWorld GameObject contains the configuration for the world generation. The ProceduralWorld component is a simple script based on perlin noise, which it uses to randomly place trees, bushes and rocks in the world. As the player moves around, it will also remove old objects behind the player, and add new ones in front of the player.

In a nutshell, what it does is that it generates a grid of tiles, and inside each tile it generates a number of objects based on the perlin noise density. The perlin noise can be scaled up, to produce smoother variations in the number of objects, or scaled down to produce noisier variations.

This kind of noise-based world generation algorithm is used in many games (e.g. Minecraft) to generate terrain and other objects in the world. Though, in a real game they are often much more complex and have more features, like caves, rivers, biomes, etc.