Book of Dreams


Responsibilities

Gameplay Programming, AI, Design, Prototyping, Tools

Project Length

August 2014 – May 2015

Book of Dreams is a 2D beat-em-up where 1-4 pillow-wielding players fight their way through a vibrant dream world. As a sequel to Oneironauts, the game focuses on fun, energetic combat encounters with mysterious enemies like cavities, and a reverse mermaid.

Book of Dreams was developed as a senior project at DigiPen by a team of 8, of which I was primarily a gameplay and AI programmer.

AI NavGraph

Although Book of Dreams is a 2D game, the players and enemies can move forward and backward as well as side-to-side, virtually forming a 3D space. Since this space can be obstructed by objects and characters, one of my first priorities when starting the AI for the game was the pathfinding system.

Unity has a built-in NavMesh, but unfortunately it’s intended to create NavMeshes on the x-z plane whereas Unity’s 2D workflow utilizes the x-y plane. Sprites and objects could be rotated to match the mesh, but this would make Unity’s 2D physics and camera system impractical. So, it made more sense to create a custom pahtfinding solution – and that’s what I did.

Fortunately, Unity provides some nice tools that can be utilized for AI navigation. Particularly, Unity’s PolgonCollider2D, which allows users to edit a 2D polygon from within the Unity Editor. Using this as an editing framework, I created a system to generate a corner graph based on the polygon. This meant we got nice editing interface for free, and I just needed to implement the graph logic.

The idea is fairly simple: a pathfinding node is added at each concave vertex of the polygon, then each node is linked to each other reachable node. The system also allows for adding obstacles within the NavGraph, which generates nodes on the graph with a similar approach. A partial implementation of the graph can be seen here.

Behavior Tree Debugger

In Oneironauts, state machines were used to bring enemies to life. However, moving into Book of Dreams, I wanted enemy behavior to be more open to change and scalable. With state machines, adding new states or changing the connections between the states requires a lot of overhead. So, the decision was made to utilize behavior trees for the enemies in Book of Dreams.

With state machines, simply printing the current state of an object can go a long way for debugging. However, since behavior trees could have multiple behaviors running concurrently at any given moment, debugging can be a bit trickier. Although a simple logging system could be integrated within either architecture, it’s often quicker and certainly more digestible to visually see what’s happening. This is especially true in the case of a tree. So, I developed a simple behavior debugger. It allows users to select an object within the editor and draw its behavior tree visually. The debugger displays structure of the tree as well as the current status of each node: whether it’s currently running, failed, succeeded, or if it hasn’t ran at all yet.