Wave Function Collapse

procedural generation (c#)

Summary & Purpose

I’m a big fan of procedual generation and randomness in video games, to that end I wanted to make a package for doing procedual map generation. I stumbled upon wave function collapse and it seemed to accomplish what we needed to do. I found implementations in python and C, which were for small bitmaps or images which generated the image below.

This is cool, but not immediately applicaple to what I need.

I ported a combination of these implementations to unity, while adding in the ability to use gameobjects and 3d models of “blocks” as cells.

These are examples of simple modular "blocks" which I quickly mocked up in blender. From left to right, the tiles are: blank, intersection, straightaway, turn

Minimal setup in unity thanks to some custom editor tools allows me to quickly generate maps.

20x20 map generation (slowed down with artificial delete between iterations to help visualization)

A good start, but we can get even closer to an ‘objective’ level by making this a maze. The way we can do this is by preprocessing cells allowing for one “entrance” and one “exit”.

20x20 map generation with preprocessing of cells (slowed down with artificial delete between iterations to help visualization)

This is cool and all but adding in a bit of playability goes a long way. ( Car controller scripts not made by me, just a quick asset drop while using my procedually generated roads as a surface)

Procedually generated roads to drift away on. :)

This system is currently being used as is with different blocks in a roguelike action game I’m making where it generates a procedual maze for certain levels.

Left the generated level the player is expected to traverse. Right the path through the generated maze.