Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Unity Virtual Reality Projects

You're reading from  Unity Virtual Reality Projects

Product type Book
Published in Sep 2015
Publisher Packt
ISBN-13 9781783988556
Pages 286 pages
Edition 1st Edition
Languages
Author (1):
Jonathan Linowes Jonathan Linowes
Profile icon Jonathan Linowes

Table of Contents (18) Chapters

Unity Virtual Reality Projects
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Virtually Everything for Everyone Objects and Scale VR Build and Run Gaze-based Control World Space UI First-person Character Physics and the Environment Walk-throughs and Rendering Using All 360 Degrees Social VR Metaverse What's Next?
Index

Chapter 3. VR Build and Run

Yeah well, this is cool and everything, but where's my VR? I WANT MY VR!

Hold on kid, we're getting there.

In this chapter, we are going to set up a project that can be built and run with a virtual reality head-mounted display (HMD) and then talk more in depth about how the VR hardware technology really works. We will be discussing the following topics:

  • The spectrum of the VR device integration software

  • Installing and building a project for your VR device

  • The details and defining terms for how the VR technology really works

Note

The projects in this book do not need to be implemented in sequence. You are free to skip around, as each chapter does not depend on its prior chapters. The exception is this chapter. Please implement the MeMyselfEye prefab, your target build device, and the Clicker class before moving on to the rest of the book.

VR device integration software


Before jumping in, let's understand the possible ways to integrate our Unity project with virtual reality devices. In general, your Unity project must include a camera object that can render stereographic views, one for each eye on the VR headset.

Software for the integration of applications with the VR hardware spans a spectrum, from built-in support and device-specific interfaces to the device-independent and platform-independent ones.

Unity's built-in VR support

Since Unity 5.1, support for the VR headsets is built right into Unity. At the time of writing this book, there is direct support for Oculus Rift and Samsung Gear VR (which is driven by the Oculus software). Support for other devices has been announced, including Sony PlayStation Morpheus. You can use a standard camera component, like the one attached to Main Camera and the standard character asset prefabs. When your project is built with Virtual Reality Supported enabled in Player Settings, it renders...

Creating the MeMyselfEye prefab


To begin, we will create an object that will be a proxy for the user in the virtual environment. This will be helpful later on, and it will simplify the conversations in this book, since different VR devices may use different camera assets. Like an empty vessel for your VR soul...

Let's create the object using the following steps:

  1. Open Unity and the project from the last chapter. Then, open the Diorama scene by navigating to File | Open Scene (or double-click on the scene object in Project panel, under Assets).

  2. From the main menu bar, navigate to GameObject | Create Empty.

  3. Rename the object MeMyselfEye (hey, this is VR!).

  4. Set its position up close into the scene, at Position (0, 1.4, -1.5).

  5. In the Hierarchy panel, drag the Main Camera object into MeMyselfEye so that it's a child object.

  6. With the Main Camera object selected, reset its transform values (in the Transform panel, in the upper right section, click on the gear icon and select Reset).

The Game view should...

Build for the Oculus Rift


If you have a Rift, you've probably already downloaded Oculus Runtime, demo apps, and tons of awesome games. To develop for the Rift, you'll want to be sure that the Rift runs fine on the same machine on which you're using Unity.

Unity has built-in support for the Oculus Rift. You just need to configure your Build Settings..., as follows:

  1. From main menu bar, navigate to File | Build Settings....

  2. If the current scene is not listed under Scenes In Build, click on Add Current.

  3. Choose PC, Mac, & Linux Standalone from the Platform list on the left and click on Switch Platform.

  4. Choose your Target Platform OS from the Select list on the right (for example, Windows).

  5. Then, click on Player Settings... and go to the Inspector panel.

  6. Under Other Settings, check off the Virtual Reality Supported checkbox and click on Apply if the Changing editor vr device dialog box pops up.

To test it out, make sure that the Rift is properly connected and turned on. Click on the game Play button...

Build for Google Cardboard


Read this section if you are targeting Google Cardboard on Android and/or iOS.

A good starting point is the Google Cardboard for Unity, Get Started guide (for more information, visit https://developers.google.com/cardboard/unity/get-started).

The Android setup

If you've never built for Android, you'll first need to download and install the Android SDK. Take a look at Unity manual for Android SDK Setup (http://docs.unity3d.com/Manual/android-sdksetup.html). You'll need to install the Android Developer Studio (or at least, the smaller SDK Tools) and other related tools, such as Java (JVM) and the USB drivers.

It might be a good idea to first build, install, and run another Unity project without the Cardboard SDK to ensure that you have all the pieces in place. (A scene with just a cube would be fine.) Make sure that you know how to install and run it on your Android phone.

The iOS setup

A good starting point is Unity manual, Getting Started with iOS Development guide ...

The device-independent clicker


There is one more thing I want to do, which will be very helpful in later chapters of this book. At the time of writing this book, VR input has not yet been settled across all platforms. Input devices may or may not fit under Unity's own Input Manager and APIs. In fact, input for VR is a huge topic and deserves its own book. So here, we will keep it simple.

As a tribute to the late Steve Jobs and a throwback to the origins of Apple Macintosh, I am going to limit these projects to mostly one-click inputs! Let's write a script for it, which checks for any click on the keyboard, mouse, or other managed device. (I have provided a detailed introduction to the Unity scripting in the next chapter, so please just follow along for now):

  1. In the Project panel, select the top-level Assets folder.

  2. Right-click and navigate to Create | Folder. Name it Scripts.

  3. With the Scripts folder selected, right-click and navigate to Create | C# Script. Name it Clicker.

  4. Double-click on the...

How virtual reality really works


So, with your headset on, you experienced the diorama! It appeared 3D, it felt 3D, and maybe you even had a sense of actually being there inside the synthetic scene. I suspect that this isn't the first time you've experienced VR, but now that we've done it together, let's take a few minutes to talk about how it works.

The strikingly obvious thing is, VR looks and feels really cool! But why?

Immersion and presence are the two words used to describe the quality of a VR experience. The Holy Grail is to increase both to the point where it seems so real, you forget you're in a virtual world. Immersion is the result of emulating the sensory inputs that your body receives (visual, auditory, motor, and so on). This can be explained technically. Presence is the visceral feeling that you get being transported there—a deep emotional or intuitive feeling. You can say that immersion is the science of VR, and presence is the art. And that, my friend, is cool.

A number of...

Summary


In this chapter, we discussed the different levels of device integration software and then installed the software that is appropriate for your target VR device. Setting up is not necessarily the smoothest process, but there are plenty of us early adopters doing it, so you can get help on the Internet if you get stuck. We also discussed what happens inside the hardware and software SDK that makes virtual reality work and how it matters to us VR developers.

In the next chapter, we'll work more on the Diorama scene and explore techniques to control objects in virtual reality. From a third-person perspective, we'll interact with objects in the scene (Ethan, the zombie) and implement look-based control.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Unity Virtual Reality Projects
Published in: Sep 2015 Publisher: Packt ISBN-13: 9781783988556
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}