Case Study: Procedural Level Generator
The focus of this project was to learn how Unity's Object Component system worked, as well as learn how to set up a level that could build itself at runtime including the Player, the Goal & Enemies. I've always been drawn toward procedural design, and so my first real challenge with this project was to code my own Level Generator. I also modeled the pieces that made up the level. For the Player and Enemies, I didn't spend too much time on them as they were outside the focus here.
I created models for each grid tile in the theme of a raised platform over a grassy field. These tiles can be easily swapped out for a change in scenery in later levels, or add a challenge with walls & obstacles. The tiles that don't have any bridge models on them can also be randomized to add trees or other obstacles too.
Here are a few results of the core idea of this project: The Level Generator. It exposes to Unity's editor as many variables as it can to allow for quick customization without requiring code re-writing. Object spawn locations are based on the tiles, and even the tile pathing algorithm can also be swapped out for different patterns.
The Opportunity
The game's mechanics are centered on the physics of launching the ball and bouncing it off surfaces.
Use physics to launch the ball and aim for the floating goal. But there's a catch: The ball must be the opposite color of the goal. Just like magnets repelling & attracting, the ball will be drawn toward its home if it's the opposite color. To change its color, simply hit it against a surface.
Here's the focus of the project, the Level Generator. It spans 3 frames, utilizing multiple components firing Events to each other.
The Challenges
The player shoots the ball as a standard golf game, and accumulates a score based on several factors. Several more features are planned, such as unlockable areas and interactable objects.
Several objects and items are also generated within the level. These items act as bonus incentives to challenge the player to use the environment to their advantage and master the physics.
What I Learned
S.O.L.I.D. Principles
These five methodologies have proven to be invaluable to my learning as a Game Developer. While writing the scripts and building prefabs, I try my hardest to maintain them in order to prevent disorganization or errors, as well as allow easy modifications and extensions. While I am still learning about how to properly implement these essential practices, lots of time is spent reviewing and refactoring where needed, and I am constantly refining my workflow and learning new techniques.
Variable Access Protection
I've learned first-hand of the importance of protecting modifications to variables. Implementing Properties rather than variables allows for a higher level of protection by ensuring that the correct processes are executed. Events, for example, are the main effects from a variable being modified, as other scripts need to know when something has changed.
Folder Structure & Pipeline
The first thing I tackled was the Level Generator. I was excited to get into the algorithm and build a puzzle for my future-self to solve. I organized it well enough for being a prototype, but I learned that if I plan on expanding it out into a full game, it must be packaged into a modular drag-and-drop prefab. It should not require code refactoring just to fit in with other systems.
When I got around to making a main menu, I realized that a system for passing data between scenes requires it's own similar package that is able to communicate with the Level Generator. This idea should flow in line with the Solid Principles, but is just as significant to warrant its own case study for future projects.