Eye Spy with My Little Eye

Over the last four days I’ve been steadily working on a game called ‘Little Soul’.  It’s a small three week game where players play as a roomba who has to clean a level before the time runs out.  Now I’m not very good with scripting but for this project I put my hand up to handle all the menu’s and also the main camera for the game play.  I thought I was taking a task that wasn’t too difficult but I didn’t factor into my thought process that as a roomba, the game space is firstly ten times the size it normally is (roomba is roughly 1/10th the size of a person which mean the level has to be x10), and secondly the perspective of the roomba is completely different to that of a normal 3rd person game.  As usual I unwittingly made life harder for myself.  Karma I guess.

Firstly, the menu screen.  Now for those that don’t know Unity recently overhauled their UI system’s basically removing or making redundant GUI’s.  Or at least the way we used to handle GUI’s.  Now it is a much more user-friendly canvas system that includes all the UI functionality you would hope for.  Some of the great features of this system is removing the need to script every tiny detail of button interactions and the much dreaded scaling functionality(I still don’t understand how to do it).  So far I have the basic buttons needed plus script functionality and the title.  This is phase one of the menu system, the next and final phase of the menu I can only complete once the level and roomba is finished.  My plans for the menu is to have the level in the scene with the roomba sitting next to the menu buttons and when the player highlights a button the roomba reacts with it’s animations.  Pretty nifty ey?  But I can’t even begin to tell you how much better this system is over the old GUI system, just look at the two pictures below.  The first picture is a script I had from an earlier game I did, the second picture is from this game.  That’s how much work the new UI system has saved me.

Screenshot 2015-04-19 21.19.12   >  Screenshot 2015-04-19 21.19.38

Now onto the the camera controller.  I’ve never really done a camera controller before.  Normally what I do is simply attach the camera to the player and it does exactly what I want it to do.  But for this game, the camera has to not only constantly show the player the state of the roomba (which shows battery life and garbage cleaned), but it also has to reveal enough of the massively scaled level so that the player can make informed decisions.  Attaching the camera to the player at such close range only makes the experience jarring and doesn’t achieve the goals we need it to.  I needed to script the camera so that it would follow the player in a smooth comfortable fashion.  I also had to add in the flexibility so that it could be constantly tweaked during the development process as level scales, viewing perspective and other requirements could all change later on down the road.

So firstly, I needed three variables that would add the flexibility my dev team needs to adjust the camera whenever changes are made.  These are, how far above the roomba I want the camera to be, how far back I want the camera to be, and how smooth I want the camera to follow the player.  I also had to add an empty game object for the camera to follow because at this stage I don’t know if a rigid body will be added to the roomba.  If this happens and I’m following the player, the camera will become jerky as rigidbody calculations are only made in fixed update which isn’t constant.  Next using vector maths I set the camera’s position to be up and behind the player with the values set by the above variables.  Once this calculation is made I then had to lerp the camera movement so it follows the player smoothly.  I thought I was finished at this point, but when i tested it out the camera wouldn’t rotate when the player rotated therefore it would only look in one direction.  So I added a transform.LookAt function to look at the empty game object and it works!!  Check out the below image for a visual representation of the code:

Screenshot 2015-04-19 21.19.45

So for now the camera is perfect and is working as intended.  With the variables set, me and the rest of the dev team can tweak the camera as needed when the game is more developed.  Unfortunately however it’s not finished.  As I build the level and implement furniture that the roomba will be going under I can already foresee the camera clipping through the models and causing all sorts of nightmares.  I haven’t quite figured this one out for certain yet, but I’m guessing it has something to do with rigidbodies and raycasting.  Stay tuned.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s