My Second Unity game!
I published my second unity game, “Maze5″ in android market. You can download it from here. I also created a web version. To play the web version, simply follow the link, here. (It is my public drop box, so I think this link is safe.) So, how was last week? Well, I felt sad when I heard the news that Apple’s CEO Mr. Steve Jobs has passed away. I heard the news from google+ timeline. Personally, I have not used MAC computer. I always use Windows. I think I was simply lazy to learn another OS. I may have missed many opportunities to use excellent softwares run on MAC, especially for recent years. In my opinion, I think the greatest invention for recent year is ipad. I have not bought any tablet yet. But I may better to have one, soon. By reading many tributes for him, I felt so emotional, as sharing people’s deep sorrow. Rest in peace, Dr. Steve Jobs.
Yesterday, I went to CEATEC Japan, the biggest exhibition of leading electronic technology in Japan. I put pictures in google+, facebook, twitter. If you have interests, please have a look at one of my pages.
So, this is my fifth version of maze. But this is my second application in “Unity”. Why did I choose this topic? Well, I want to make an application, using accelerator in android. Because the accelerator is such an essential input device for android. Just same as first application of “balling“, I firstly created web version and then modified it for android version.
Control the Gravity!
For a simplest prototype, let’s consider a ball on the floor. If you add “rigidbody” both a ball and a floor and set “Physics Material” properly, a ball rolls down as a floor tilt. What you need is to add keyboard input to give a direction, in which way a floor tilt.
It is not so simple..
But if we use the above method, Sometime, a ball passes through a floor. It does not detect collision properly. Why does it happen? In Unity, it uses “Discrete” collision detection, in stead of “Continuous” collision detection, in order to do the transaction effectively. Therefore very fast moving objects sometime pass through obstacles. To use “Continuous” collision detection is restricted in 2 cases. 1)Rigid body collides with fixed body. 2) Rigid body collides with rigid body. Therefore, we need to have alternative way.
In stead of tilting a floor, we change the gravity, which makes exactly same effect. What we need is to fix the floor and change its gravity direction. The variable we need to control is “Physics.gravity”. By taking the input, we set the value to this variable properly. After this, a ball moves around, according to your input. But the floor does not move. To tilt a floor visually, we need one more step. As the floor has to be fixed, we need to tilt all things except floor, such as main camera, spot light, background etc. To tilt everything in one direction, we make “Rig” which holds these components. This is easy, as you make empty game object and put other components under this hierarchy.
Other topics included
There are 2 other topics which I learned in this project. There are 1) animation and 2) rotating objects. Making animated objects in Unity are fairly easy. What you have to do is to attach animation component to the object and create the animation clip for it. The animation clip is the scenario of animation. You create it from animation view. You move the object in scene view and record it as a key frame. As for 2)rotating objects, I wanted to make a seesaw. If a object hits in one-end, the other end goes up. To do that, we need to use “Hinge joint”. When you attach “Hinge joint” to the object and designate hinge direction, it rotates around that hinge as if the axis is pinched. So, I created several obstacles, using these applications.
Customize for android
It is possible to adopt web version to android. But it is better to fix the floor for android version. As for android, it uses acceleration sensor in the device, players tilt the device. The floor does not need to be tilted anymore. Therefore, the main camera should be out of rig’s hierarchy, which fixes the floor visually.
How to play this game? (android version)
This is a simple maze game. By tilting a screen, a ball gets gravity and moves around (vertically and horizontally). The goal is a red box at left bottom corner. Yellow cylinders are traps. If a ball touches it, a ball goes back to starting point. Boxes with Leopard pattern flip a ball. After game is over, it restarts the game after a few seconds. Good Luck!
How to play this game? (Web version)
To tilt a board, use arrow keys or “A”,”D”,”W”,”S” key.(“A”, “D “are for left and right. “W”,”S” are for top and down) A board tilts vertically and horizontally.
You tube demo video
You tube demo video is here (for android). Thanks for reading! Have a nice day!