Minigame Monday: A Header the Game
A Header the Game:
- The concept:
I wanted to make a minigame in Unity this time; although python is great for getting things moving on a screen, I wanted to practice Unity's game object based style for a minigame rather than a larger project. Seeing as football is topical at the moment, I was considering doing something football related, and after coming up with the title I had to make it. For the gameplay itself, I decided to use some of Unity's 2D physics for keeping a football up, which gave me a chance to use physics materials, which is something I hadn't really looked at previously.
- The challenge:
Making a minigame in unity is (obviously) pretty different to making the same game in python. Rather than considering the core parts of programatic gameplay, such as rendering and input, Unity will handle most of that behind the scenes. Organisation is also completely different, as you're writing code based on objects it will be attached to, rather than at what point in the loop it will be executed. As a result, I ended up with two scripts attached to the ball (which was a prefab), another two on the head, plus a couple of other scripts to things such as keeping score and handling losing the game and spawning. The methodology here is to think of what behaviour you want, and then write scripts to facilitate it, rather than writing the behaviour into many different parts of the loop, so it can actually be much easier to make small additions in Unity, not to mention the fact that scripts can be reused. You just have to make sure you're aware of how that script will interact with the other parts of the gameplay!
The other challenge for making this game was making sure the objects were working in the physics as I wanted. I wanted to make it so that heading the ball would add force to the ball, so it would slowly bounce higher over time. To do this, I created physics materials for the head and the ball, and gave the head a bounciness value > 1, so that when the ball bounced against the head, the ball would bounce higher. This gave the effect I wanted for bouncing the ball on the head, but there were two other issues. Firstly, the ball would keep bouncing higher and higher until it left the screen. To fix this, I added a trigger zone just above the head, and a script that would reduce the maximum y velocity of the ball when it entered the trigger, thus limiting the maximum height the ball can go. The second issue is that the head would bounce against the walls faster and faster until it eventually clipped through them (not ideal!), however stopping the walls being so bouncy would stop the ball bouncing off them properly. The solution to this one was to split the walls into two parts; one where the head is, with low bounciness, and then the rest of the walls, which were more bouncy.
- The result:
This game proved more simple to make than I was expecting; using a large engine like Unity runs the risk of larger problems that wouldn't occur in python, but other than making sure the physics worked as I wanted there weren't really any major obstacles. There isn't much depth to the game, but I think it's proved that Unity is a solid option for minigame monday, so expect to see more in future. You can play the game at https://reddragonmakesgames.itch.io/a-header-the-game, and the code and assets are on my github.
Comments
Post a Comment