Introduction

For project I had to build a 2D platformer using some form of PCG to build three levels.

My Role

I focused on the character controller and the procedural content generation. Then, I used a data-driven approach to the pcg to help me tweaking the parameters for the level generation.

Character controller

The book AI for Games by Ian Millington inspired me to use an AI agent structure for the character controller.

Character movement State Machine diagram.

User input is handled as information captured by some sensors. Input and a geometry analysis of the level around the character consitutes the agent’s knowledge. The decision making is implemented through state machine.

Character movement State Machine C# implementation.

I used visual debug features to help while building the controller.

Some visual debug for the character controller.

The controller implements some classic jump mechanics:

  • Coyote time
  • Jump buffer
  • Dynamic gravity
  • High of jump linked to key holding (the jump will be much shorter if the key is released earlier)

PCG and tooling

I experimented with the wave function collapse algorithm to generate a platformer level. I designed several chucks for each level and defined constraints for them.

All the data the algorithm works on (settings, constraints, etc.) is defined using a data driven through a XML file. I developed a tool inside Unity to edit this file directly in engine with a functional UI.

Custom tool to edit WFC settings.

I used Unity’s coroutine to let the user decide to construct the level in one frame or performing an animation of the algorithm. This was really helpful during the development.

Animation of a level generation.

Updated: