Saturday, 10 September 2016

Driving with your Face (VR)


The Set Up

 When I did Dino Party, a VR game for the Oculus Rift, we explored several control methods that just used your head. Now obviously we found out a lot, mostly what makes you feel sick. So I decided that I should recreate some of this fun nausea for the Google Cardboard.

 Then came the decision of which mechanic to use. The Cardboard doesn't have head tracking so several of the head bobbing and weaving games were out. The gyroscope is in there. To be honest tilting your head from side to side or nodding gets a bit tiresome. So I settled on using the player's focus as the main control method, that is to say, where they direct their gaze.

 Now you can freely download Google's VR package for Unity, it comes with a lot of extra stuff that it didn't used to, I spent a while deleting all the samples and demos from it. Then I set up a simple scene, I wanted to control a vehicle of some description through a simple yet increasingly difficult task.

 Mobile games have a strong grounding in endless runners and simple minimalistic art forms, I wasn't looking to do anything ground breaking, especially when I only have the weekend to prototype the idea.

 After a bit of rejigging, I got the basics of the Cardboard working and tested. Important as the SDK has been updated, best to check it runs a build before continuing on. Apparently it creates all the VR camera stuff at run time, instead of just having a prefab with all the rig and two cameras in the editor mode.


Gameplay Mechanics

 What we need is a stage, something simple that can always be within the player's line of sight, more like an arena than a race track. I made it round, so that the player has the added difficulty of staying on it, maybe I'll add some ice later... with the aid of collider materials.

 Then it's just a case of adding a rigidbody to a cube, and then we can start programing a few mechanics.

 The most important one is a raycast from the camera to the floor, this way we can make a target for the player's car to follow. Then I add a little check to restart the game if the car falls below a certain point (off the map), later I will replace this with a death screen.

 After a little fiddling to get the right raycast, and making sure the target follows the intersection of the ray and the collider, it was just a case of finding a nice method to move the little car about, I want to make it increase in speed and also to be quite unstable, adding to the joy. I don't want the car to be able to stop, so if it reaches the target it should shoot past it and spin around towards it again.



 I did have a little fun bug, where the raycast target caught the car collider and both flew towards the camera, raycast only works for floor tag now.

 Next up, getting some random collectables to spawn about, as I am just trying to make this quick they will probably be coins or something of the type. Add a little spin, and a trigger box collider and bob's your uncle. That adds to a global score. Now before I add some difficulties or anything fancy, let's do the UI system, I want to allow for quick playing and death, no extra scenes or anything... I think it would be also nice to have a few cars to choose from, might even have to unlock them.


Menu Screen

 I kept the camera in the same place, simply adding some more bits to the foreground to act as the menu system. I only need three UI buttons; Play, Exit and Switch Car (which will run through a list of cars) I haven't decided yet how I am going to block access to the cars, perhaps I'll disable the play button if you haven't unlocked it. I have put a boolean on the car, so it doesn't speed off after the title until the play button is clicked. It all resets to this point after death.

 Cardboard only has one button, so I used the raycast again, and if it detects a left mouse click, whilst looking at the UI element it will do the action. I do this by comparing the names of the objects it raycasts, not the fastest way but we only have three buttons, so leave me alone. Below is the view from your eyes, as you can see it's quite tricky, a good thing? Yet to be determined.



 I've also added in a floating text for the score, best and last... Last will update in game. I need to find a nice font, but all that arty stuff will come later.

 That's all I've got time for today... Later I will add events, that will change the arena and incorporate more things. A few examples might be;

  • Winter; a palette change and an extra skiddy arena 
  • Ramps and banks; get some cool air for extra coins
  • Multiple height platforms 
  • Scifi; do like to mess with gravity...
  • Enemies; might add some foes, bit boring though, I want the arena to be the only foe. 

 If you have any feedback or suggestions, do let me know. 

Regards,