Devlog- Adding Procedural Generation to PUSHER

A big problem with the game up until now has been the fact that it takes entirely within an infinite dark void. To fix that, I want to add some procedurally generated terrain using Godot’s built in tilemap and noise map generation, which thankfully makes it easy.

Adding Obstacles

To make things easier for myself I’m going to be using scenes for the tiles with individual sprites. I could figure out collision within the TileMap itself some other time but the specific setup I have in mind works this way for me.

The blue outline shows the bounds of the regular hitbox that enemies can crash into, and will block player movement, and the red outline shows the bounds of the “NavHitbox”. This will be used for the enemy AI’s pathfinding to make sure they don’t graze any corners and die.

Now I need to write a script that randomly generates these at runtime. Getting where to place the tiles is pretty easy using Godot’s built-in noise generator, FastNoiseLite:

The tricky part of this is actually enabling infinite generation. To do this I’m going to use chunks.

The code above gets the current chunk (a square of 16 tiles) and puts it and every chunk near it in an array. Then, it ensures to load (aka spawn the tiles of) every chunk that’s within that array, and unload (despawn the tiles) every other chunk.

The is_obstacle function queries the noise map to see if it’s over a certain threshold, and if it’s over it will spawn a tile there.

We can also use this function in other scripts in the future to detect obstacles!

Now the tiles spawn around us!

Next I’ll be adding the ability for enemies to navigate around this new environment!