I’ve just started learning game development with Unity. I really love cats so I created a crazy game: star collecting with Nyan cat! You can either love or hate Nyan cat, but she is a colorful part of our internet history. The game is very simple, and great if you’ve got a couple of minutes of free time or you want to annoy the people around you.
Create a controller for the gameI choose an unusual mode to control a game. Instead of a mouse, a keyboard or a touchscreen, I used an Infineon 3D magnetic sensor 2GO kit with a magnetic rotator modul.
The magnetic sensor 2GO kit does its magic with a TLE493D magnetic sensor and it can detect the state of the magnet inside the rotator. It is small, clever and very accurate. That’s how you do an easy-to-use device!
The rotator can be rotated and pushed down. I use both of its functionality. I control Nyan cat’s position with the rotation and when you lost, you can restart the game by pushing down the rotator. It is very intuitive.
I used Arduino IDE to program the magnetic 2Go kit. You should follow the instruction here to program the kit with Arduino IDE and to use the sensor. I’ve written a simple sketch that sends some data through serial port. The first data is whether the button is pushed or not while the second is the rotator angle on a -1 to 1 range.
Creating a ball case for the kitI wanted to make the controller nice, so I made a casing to hide and protect the electronics. i used a polystyrol ball because it is very easy to work with them.
it is much easier to hold it in my hand while i'm playing. I colored the ball with highlighters. It looks much better like this :)
Connecting to the sensor from UnityYou can control the game objects by attaching scripts to them. I used a programming language called C# to do this. It can be used to make the controller and the game talk to each other using serial communication. To use this feature you have to navigate in the Unity Editor to File/Build Settings…/Player Settings…/Other Settings/Api Compatibility Level* and set it to .NET 2.0. After that you can use the serial communication module of the C#.
When you launch the game you can select the parameters of the serial connection before the game itself would start.
The images in unity called sprites. I was looking for sprites for the game when I found this project. These are basically just animations, but these are all the animations that I needed, so I turned this project into a real game. I made Nyan cat move, added collision detection, points, etc. It was pretty easy. I’m a beginner and it took me about an afternoon and an evening to make the game.
The game isn't too difficult, but you can't miss any stars or it is game over. Catching the first star is just as easy or difficult as catching the 150th star. It is similar to an easier Flappy Bird in difficulty. At first it might seem to be difficult, but after a couple of minutes it becomes very easy.
The state of the rotator converted to Nyan cat's position, meaning that you can go down and appear on the top of the game.
I hope you like my game! :)
Comments