Adventures in Unity (Patreon)
Content
Hey everyone!
New video is coming along nicely, but I just wanted to chat about something else I've been doing. And that's learning Unity! It was my new year's resolution for 2021, and I've been doing a little bit every week all year.
I started with tutorials. I found Tom Francis's tutorial series to be pretty helpful, and enjoyed following along as we made a top-down stealth shooter with vision cones and spawning enemies. It took weeks and weeks to follow these hour-long episodes, but it was an enjoyable experience.
But then I tried to make something myself and realised... none of it had really gone in! I had a few of the fundamental ideas of Unity under my belt - like making "prefab" versions of objects, and making "public" variables that you can see and change from the editor - but most had gone in one ear and out the other. I was lost!
So today I decided to try something different. I was gonna make a game from scratch, using what I could remember from Tom's tutorials and then Googling (and asking on the GMTK Discord) for everything else.
I decided the best thing to do was to recreate an existing game. This is a really good way of learning, I think. You don't need to come up with ideas or change the design as you go. You know exactly what you need to make, can plan ahead, and you can play the real game to see what the final outcome should look like.
I decided to recreate the iPhone game "Pop the Lock". It's an incredibly simple game: a cursor automatically rotates around a circular track. There's a coin on the circle. Tap the screen when your cursor's on the coin to score a point. At which point the cursor changes direction and speeds up, and a new coin appears.
It's super simple, but that was in my favour. I should be able to make the whole thing myself without too much trouble.
And... I did it!
2D games are actually 3D in Unity.
I started by making the simple graphics in Photoshop and putting them into Unity as sprites. I used a handy function called "RotateAround" to have the cursor rotate around the middle of the screen.
I made a coin appear, and then used Unity's collision detection system to check if my cursor was colliding with the coin. If the player hits the space bar when this is true, the score goes up.
The hardest bit was placing the next coin. It was easy to have it appear in a random point on the ring, but that's not how the iPhone game works. Instead, it should appear slightly ahead of where your cursor is now heading, at a random distance away. Rotation is always a bit tricky - especially because Unity works in quaternions: a barmy three-dimensional (four, maybe?) unit for describing axis-angle rotation. Luckily, there are some functions to make it simpler.
Anyway: that was about it. I just needed some logic for score and failure and it was done. I could have added particle effects and sounds and screen shake, but that wasn't really the point of the exercise.
Really, I was trying to learn the overarching structure of Unity. One of the tricky things with the engine is having two things talk to each other. Say: making the score go up when you win: that's my "Game Logic" object chatting to my "Cursor" object. In Game Maker, that's effortless - in Unity, there's a bit more to it as you need to essentially wire up a custom phone line between these two objects.
But anyway. This might look like a really simple project (especially to any programmers reading!), and I'd totally agree. But it was more of an exercise for me - can I make something work in Unity without just following tutorials and replicating code?
Because ultimately I want to get to the point where I can have an idea for a game and then wire up a prototype in a few days. That requires a lot of confidence in how things work, and a knowledge of many parts of the engine. And so I'll need to do more experiments like this before I get to that point.
But I'm happy with today's efforts. Baby steps and all that. And I'm looking forward to my next project. Any recommendations for games I should try and recreate?
Speak soon
Mark