Google Cardboard: Building Agency into a VR Experience

Posted by Bryan Weber on Jun 17, 2016 11:15:43 AM

If you are looking to dip your toe into the world of Virtual Reality development, Google Cardboard is the logical place to start. The Unity integration is easy and the headsets are cheap– if not free, if you eat at McDonalds (and live in Sweden). Without a ton of work you can get a VR app running on a iOS or Android device.  

However, without an easy way to connect a controller or keyboard for use with a Google Cardboard app, user input options are somewhat limited. This greatly reduces the type of VR apps you can build for Google Cardboard v1.

Enter Google Cardboard v2. The newer (but still cheap) Google Cardboard v2 headsets includes a simple “conductive input” button that taps the middle of the device's screen. This is a simple and straightforward solution to the lack of input problem: user hits the button and a tapper touches the screen. Given that any device used with the Cardboard will have a touch screen, this approach works great for capturing a single input command.

Even with just one input option, it takes the Cardboard out of the VR viewer space into the world of interactive VR experience, where users can actually affect their virtual world. It’s no Oculus, but it’s pretty awesome for only $15.

intrepid_blog_illustrations_2_Bryans_Google_Cardboard_Input_Button.png

As a developer, capturing the tap event requires only a few lines of code in Unity. While not built into the Cardboard iOS SDK, the Unity API provides for detecting screen touch events. The code below is all you need to detect the input button tap:

void Update () {

       foreach (Touch touch in Input.touches) {

           if (touch.phase == TouchPhase.Began) {

           //ADD ACTION HERE   

           }

       }

   }

You can include this code to any script attached to a game object in your scene and you will now be able to trigger an action in the virtual world.

The most obvious use would be to fire an object in a first person type shooter game. For example, if you had PlayerShooting script on your Player game object with a Shoot method, you could use the touch input to trigger the Shoot method as shown below.

using UnityEngine;

public class PlayerShooting : MonoBehaviour
{

void Update () {

       foreach (Touch touch in Input.touches) {

           if (touch.phase == TouchPhase.Began) {

           Shoot()  

           }

       }

   }

Void Shoot() {

//ADD SHOOTING LOGIC

}

}

Even though the Android SDK provides screen touch detection at the Java level, capturing a tap within Unity makes it easy to directly interact with Unity game objects.   

The jump from no input to one input really opens up the Google Cardboard v2 to more interesting use cases. Within the gaming field, the obvious uses could be for shooting or controlling the movement of a player.

However, beyond gaming, touch input could be used to select items within a virtual reality environment, such as user input buttons, photos, and videos. A user could scroll through a list of VR videos and start playback of a video, all without removing their device from the Google Cardboard.

With the addition of just one input button Google Cardboard v2 allows for apps where users can truly interacting with a virtual world, instead of just being a passive viewer.

Topics: Virtual Reality, VR, Google Cardboard, Android

About Intrepid

Intrepid is an end-to-end mobile design and development company with offices in Cambridge, MA and NYC. We help companies, from startup to enterprise, boldly navigate their mobile future. We provide our clients expertise in development, design, strategy, and technology integrations. At Intrepid, we are creating the best mobile products at the intersection of humanity & technology. Find out more at intrepid.io

Subscribe to Email Updates