Unity – Roll a Ball

Today I was following multiple different tutorials on how to use the basics within Unity. This is a game engine and a software that is used to make games. When I first opened the software I had a play around with the different mechanics and physics that were available to me, I learnt how to add objects and resize and texture them. I also added a movable character along with a ball that has rag-doll physics so that it can be moved by the player. I had created two goals along with spotlights above the playable area. The only problem with this game I created was that it had no basic mechanics, such as a scoring system.

capture

Once I had gotten a little bit familiar with the software I began to follow a tutorial on how to create a simple game called  Roll a Ball. The first steps of the game creation were to make a plane and add a material to it. I made the lane purple so that the white ball would stand out against it. Once I had the plane sorted I began to add walls, I did this by adding the 3D cube object and resizing it and then moving it to fir the edges. The ball was also added however this was not yet controllable.

snippet-1-roll-a-ball

Once I had the basic structure of the game I was able to code the ball so that it was controllable by the player. I did this through the use of scripting using C#. I found the necessary code that was required on unity’s website and added the script to the object.

player-code-roll-a-ball

The code worked and the ball was now a movable object however the camera was now an issue as it did not follow the player and it made the game almost unplayable. I did the same step as before and found the necessary code that was required and inserted it. The code made it so the camera would follow the players object which is the sphere.

camera-code-roll-a-ball

After these steps were done the game began to be playable however there was not exactly an objective so a new pick up item was added to the game. The pick ups are another object that was added the the scene. They are simply cubes that have been resized and rotated. To make them more appealing to the user we added another piece of scripting that would allow these pick ups to rotate.

pick-up-rotate-code

This is what the game looked like once I had copied and pasted the object in numerous times. so that the pick ups could be easily copied and to keep the same code they were all attached to each other, as you can see in the Hierarchy on the left side of the screen.

snippet-2-roll-a-ball

Below a quick snippet of how the game runs, you can see that the ball is controllable and the camera works correctly. The ball can also not leave the walled area and the pick ups spin around as they should; however they can not actually be picked up yet.

half-way-done

Leave a comment