Welcome to the third installment of The Brick Dead Project, a series of articles chronicling my misadventures to create a video game from scratch in the Unity 3D game development engine with no prior knowledge, experience, or clue. To catch up on previous posts in this series please click here.
Disclaimer: I am not the guy to learn this stuff from. These are the real, no BS adventures of the Starship Grandpop as I attempt to decipher the infinitely complex art of video game creation with no preparation or thought. Anything I say can and, probably, will be wrong. Enjoy the show!
Little did I know when I embarked on this little journey that I would not be learning not just one language (Unity), nor two languages (Unity and C#), but THREE languages (Unity, C#, and Math). Everything a computer does is math. We all know this yet we take it for granted, especially in this ooey-GUI world where every value and command is obfuscated by a dozen pictures. Computers are math. Video games are math on top of real-time math. 3D video games are math on real-time math on three-dimensional math. It can not be understated the shocking scale of the math involved. We’re talking Big Math. Hard Math. Big, Hard Math that will do unspeakable things to you in the shower if you drop the parenthesis. Now, you don’t actually have to solve the Math, but you do need to know it’s there, know when to use it, and know how to best leverage it. It is one thing to know that speed=distance/time. It is quite another to be staring at a ball on the screen and think about how your going to measure all those values yourself in a world that doesn’t really exist.
How bad does it get? Let’s start with the very basics. A vector looks like a point in 3D space defined by an X, Y, and Z coordinates. Except it’s not actually a point. It’s a direction. A direction from the origin of the world to your object, more specifically. It also has a magnitude, which isn’t actually one of the three numbers that defines it, but a whole ‘nother batch of Math altogether, possibly Euclidian, which sounds like a delicious flavor of ice cream. Anyway, you’re usually going to ‘normalize’ the magnitude of your vectors to be 0 or 1 for movement and… Video Games. Also, ‘normalize’ is a really hard thing to Google. Alternatively, you can ‘lerp’ or ‘slerp’ it which stands for ‘linear interpolation’ and sounds like a great thing to do to Euclidian ice cream. I do know that you can subtract the vector of your thing from the place you want to get to and it’ll automagically go there thanks to the power of… Confucianism, I think. Then, of course, things don’t just exist, but they’re facing certain directions. That brings us to ‘quaternions’ which are somehow fourth-dimensional, describe a rotation, and Wikipedia defines as: “Look, kid, you don’t want to know.”
Let me bring this back down to Earth for a moment with a little example: When you fire a gun in Call of Duty and hit someone to make red pixels fly out you are, quite literally, invoking Math on par with what was used to put men on the moon. This, more than anything else, is the reality of video games. So… Yeah, Call of Duty is rocket science.
That said, you can go surprisingly far while knowing little to none of this. I mean, once you get that blood spray in your modern military murder manager pointing the right way, you’re just going to cling to that one equation for the rest of your life. The really nasty stuff mostly comes into play when developing AI or ways to keep the camera on your player. Or vehicles. Or physics. Or… Okay, it comes up a lot. Still, Unity is jam-packed with little ‘helper’ values to demystify some of the math if you can crack Unity’s code. For example: “Vector3.up” always points up in the world where as “transform.up” points to what an object thinks is up. There’s even Quaternion.Identity which is shorthand for “I don’t give a s—t about rotation.” Additionally, a chatty Internet coupled with Unity’s buy-in investment of free means there’s a lot of help to be found out there and a lot of code snippets to copy.
Of course all the knowledge in the world won’t help if you don’t know which way is up.