Building Unity's space shooter tutorial
This weekend I found time to continue learning about the Unity game engine and development environment. The second tutorial is a simple vertical scrolling space shooter game. My implementation of the project is on Github.
Space Shooter is a lot more complex than the Rollerball game so it's a good introduction into game making. Rollerball was a great way to learn how to use the Unity editor and think about game objects. Space Shooter comes with some pre-built assets including models, materials and music useful for wiring something more complete together.
I was initially a little surprised to learn that the essentially 2D game was built with 3D models using a fixed camera. This made it easy rotate and tilt the on-screen objects and make the most of Unity's lighting system. It would be possible to achieve many similar effects with the editor in 2D mode, with considerably more work animating sprites, but the 3D approach is easy and fairly intuitive.
The game is implemented as a fixed camera, a player-controlled ship object which can only move within a predefined area, and a background. Asteroids then appear and move from the top of the screen to the bottom and serve as the primary hazzard.
The tutorial spends some time explaining how to build the prefabricated game objects from the supplied assets then goes on to cover how to add behaviour one piece at a time. The basic input control is similar to that found in Rollerball. It gets more interesting when you start setting up collision detection, spawning hazzards, destroying objects when they're off-screen or have expired. Adding the ability to shoot and handling collisions between the shot and the hazzards added another dimension to the game. Adding a scoring mechanism and simple restart function rounded out the basic playable experience.
Once the game is in a functional state, there are a few more extensions to make the player experience a little better. Getting the background texture to scroll creates the illusion of movement. Adding a particle effect over the background enhances the effect. Adding more variety to the hazzards and makes the game feel more natural. After all that, we add an enemy ship type to the hazzards and give it the ability to shoot and perform simple manoeuvers.
At this point we have a complete little game that my non-technical partner found equal parts fun and frustrating for a few minutes. It's easy to imagine how the game could be expanded further with power-ups, a hitpoints/damage system, extra lives and more levels with different challenges to overcome.
I'm having a lot of fun playing with Unity. I'll look at the next tutorial when I can.