Unity Game - Breakout
I finally tried Unity. We’ve all heard the success stories of indie devs hitting it big with their Unity games, so I figured it was a great opportunity to expand my skills and get the lay of the land in case I ever have the Million Dollar Idea. I’m already familiar with gaming paradigms, so I didn’t need an overly formal introduction like I needed for something like AWS. I chose to create a basic 2D game before attempting to move into 3D. Luckily, the good people of the internet have created a wealth of free tutorials and Stack Exchange threads over the years, so the process wasn’t painful at all.
GITHUB ➤
I chose to recreate a game called Breakout. It’s very simple, but still allowed me to work with many basic gaming concepts like player movement/controls, UI, level generation, physics, collision detection, and scoring.
EXPANDING THE PROJECT
I wanted to go a bit further than a simple recreation of a classic game, though. Unity has an entire physics engine that I could take advantage of, so leaving the project as a simple frictionless zero-gravity collision/reflection simulator seemed lame. Getting the paddle to the right place wasn’t really challenging in that environment. I wanted to introduce some of the mechanics you’d expect in a real paddle sport to give the player more control over the ball.
The video tutorial I used while building this project was a great resource, but it definitely cut some corners. The most egregious (to me, anyways) was altering the invisible collision geometry of the paddle to allow angled hits. The paddle looked like a rectangle, but behaved like a trapezoid. To me, this is a huge no-no in game design. Just because the player doesn’t see something doesn’t mean they won’t feel it, and while sneakily changing collision geometry is one way to add complexity to a flat game, it’s not the way I wanted to do things.
Instead, I added the ability to tilt the paddle left or right by about 20 degrees. I also introduced some friction into the system and allowed the ball to spin. These simple changes made the game way more dynamic. Hitting the ball at the right angle while moving the paddle can radically change the ball’s speed and angle of reflection. It’s possible to speed up or slow down the ball by hitting it differently, so I wanted to incentivize fast play. I added a scoring system with a point multiplier for successive hits. When the ball is at its starting speed, the multiplier has time to tick back down to 1x between hits, but as time between hits decreases, the multiplier rises to a maximum of 3x for rapid combo hits. As you saw in the demo footage, the game can get fast enough that even its creator has a hard time keeping up.
CHALLENGES
One of the main challenges was dealing with soft-lock conditions. Because my system included friction, it was possible for a ball to collide with a surface at a low angle of incidence and change to a flat trajectory. The ball would then endlessly bounce horizontally between the screen boundaries and the game had to be restarted. To prevent this, I detect when the ball enters a flat trajectory and add some force to nudge the ball downward slightly. The ball can still get stuck in a flat vertical trajectory along the screen boundaries, but the paddle can be angled and used to get the ball off of the wall.
The most challenging thing to get right was difficulty. Thankfully, Unity has the ability to make code variables accessible in the editor via [SerializeField], so it was just a matter of changing the ball and paddle speed while playtesting. Of course, I based all of these decisions on my existing gaming skills and familiarity with the game, which became painfully obvious when I let my family try it out. Watching them struggle, I immediately realized why modern games have begun moving toward dynamic difficulty. There's such a skill gap in gaming that it seems almost impossible to design a one-size-fits-all difficulty setting with the expectation that the player can improve to meet it. Difficulty will be among my first considerations when developing future games.
THE FUTURE
As I developed, I had tons of ideas to improve the game. Dynamic level generation, improved graphics, brick breaking animations (or better yet, particle systems), power-ups…the list goes on. Nothing seems impossible in Unity, and I may revisit this project to implement or test some of those ideas. It’s more likely that I will move on to a more in-depth project for my next game, though. I want to develop a mobile game, because frankly that’s where the market is. If Flappy Bird can succeed, so can I!
Thank you for reading! If you have any questions, feel free to contact me.