The assignment for this week is to recreate the classic game Pong using what we know in Unity.
This challenge has an extra level of depth in that the Unity engine is extremely slanted towards making 3D games. Recreating Pong and trying to make it convincingly look like the original required a bit of thinking.
Main thing I did was make excessive use of the Toon Shader package that comes with Unity. Toon Shader allows you to create cel-shaded objects which, conveniently enough, always render as “flat” shapes regardless of camera angle or lighting. The other thing I did was switch the main camera from perspective to orthographic view. Orthographic view displays everything as though viewed directly from the side, instead of how it would look from the perspective of the camera. This causes things like boxes to just look like squares and spheres to just appear as circles.
The finished game can be downloaded here. However, this is not my final submission for the assignment. The assignment also offers bonus points for expanding Pong by adding new gameplay. So, stay tuned for Pong: The RPG: The Movie: The Game.
Until then, lets talk a bit about programming. It has come to my attention that some of my classmates may be struggling with how to program their games, so I’m going to try and share some tips.
First off, games are programs. You need to program them. Yes, in the big glamorous world of AAA titles, games are created by teams of programmers dictated by an idea man who probably slouches in his cushy chair and sips martinis. You are not an AAA game developer. At least, not yet. Someone needs to program your game, and, for now, that person is YOU. Don’t be scared. Don’t tell yourself “I’m not a programmer.” Just roll up your sleeves and try. Are you not a programmer? Then BECOME a programmer.
Programming isn’t about memorization. No sane person can memorize each and every little nuance of how to do something. You’re going to be looking things up. A lot. Unity is very well-documented. You can find the library documentation here, but I find that the best place to start is on the page for MonoBehaviour. All scripts are MonoBehaviours by default, so looking up the documentation for it will tell you what all the different things like Update, Start, OnTriggerEnter, and the like do. Clicking on the different function names will take you to pages explaining in detail what they do and oftentimes showing a good example of how to use that function. Don’t be afraid to look around to figure out how to do what you want to do! If you can’t quite find what you need there, Google is your friend. Anything I didn’t learn in class, I’ve learned by typing “how do I [blah] in Unity” into Google.
And, finally, the BIG trick to programming something is to take it apart into as small bits as possible. For example, there is no such thing as “programming an AI.” The Singularity hasn’t happened yet. Machines don’t think for themselves. What you CAN do, however, is program something to act like it CAN think. Lets take my Pong recreation as an example.
What would an AI controlling a paddle do? Try and move the paddle towards the ball, right? But how do you do that? We need to break that simple action even further down. The computer needs to look at where the ball is in relation to the paddle, and then move the paddle in that direction. So, my AI compares the Z coordinate of the ball to the Z coordinate of its paddle. If the ball is higher than the paddle, the paddle needs to move up. If the ball is lower than the paddle, it needs to move down. If the ball is just about level with the paddle, it shouldn’t move at all.
Just following this simple approach works, but the result is a nigh-unbeatable AI who can perfectly track the ball. What causes humans to miss in Pong? Human reflexes are not perfect. At any split-second, a person may fail to recognize that they need to move their paddle towards the ball. To reflect this, my AI has a random chance of “spacing out” and not moving the paddle at all. This results in an AI that will try to block the ball, but is capable of making mistakes.
Hopefully this little walk through my “AI” designing process will help you see how to go about designing and programming things in your own games. Just remember: Break everything down into small steps and don’t be afraid to look things up or ask questions.