Today, we are witnesses to the burgeoning of virtual reality (VR), an exciting new technology that promises to transform in a fundamental way how we interact with our information, friends, and the world at large.
What is consumer virtual reality? By wearing a head-mounted display (such as goggles), you can view stereoscopic 3D scenes. You can look around by moving your head and walk around by using hand controls or motion sensors. You can engage in a fully immersive experience. It's like you're really in some other virtual world.
This book takes a practical, project-based approach to teach you the specifics of virtual reality development with the Unity 3D game engine. We walk through a series of hands-on projects, step-by-step tutorials, and in-depth discussions using Unity 5 and other free or open source software. While VR technology is rapidly advancing, we'll try to capture the basic principles and techniques that you can use to make your VR games and applications immersive and comfortable.
You will learn how to use Unity to develop VR applications that can be experienced with devices such as the Oculus Rift or Google Cardboard. We'll cover technical considerations that are especially important and possibly unique to VR. By the end of this book, you will be equipped to develop rich, interactive virtual reality experiences using Unity.
Chapter 1, Virtually Everything for Everyone, is an introduction to the new technologies and opportunities in consumer virtual reality (VR) as regards games and non-gaming applications.
Chapter 2, Objects and Scale, discusses how you can build a simple diorama scene. It introduces the Unity 3D game engine as well as Blender for 3D modeling and explores the issues of world coordinates and scale.
Chapter 3, VR Build and Run, helps you configure your project to run on a VR headset, such as the Oculus Rift and Google Cardboard (Android or iOS). Then, we go into detail about how the VR hardware and software works.
Chapter 4, Gaze-based Control, explores the relationship between the VR camera and objects in the scene, including 3D cursors and gaze-based ray guns. This chapter also introduces Unity scripting in the C# programming language.
Chapter 5, World Space UI, implements many examples of user interface (UI) for VR, which includes a heads-up display (HUD), info-bubbles, and in-game objects with a lot of code and explanations.
Chapter 6, First-person Character, dissects the Unity character objects and components, which are used to build our own first-person character with gaze-based navigation. Then, we'll explore the experience of having a first-person virtual body and consider the issue of motion sickness.
Chapter 7, Physics and the Environment, dives into the Unity physics engine, components, and materials as we learn to work with forces and gravity in a number of VR project examples and games.
Chapter 8, Walk-throughs and Rendering, helps us build a 3D architectural space and implement a virtual walk-through. We also talk about rendering in Unity and performance optimizations.
Chapter 9, Using All 360 Degrees, uses 360-degree media in a variety of projects, including globes, panoramas, and photospheres. We also have a discussion on how it all works.
Chapter 10, Social VR Metaverse, explores the multiplayer implementations with VR using the Unity 5 networking components. We also have a look at VRChat as an example of an extensible platform for social VR.
Chapter 11, What's Next?, in this chapter the author comments about the potential of this exciting technology.
Before we get started, there are a few things that you'll need. Grab a snack, a bottle of water, or a cup of coffee. Besides this, you'll need a PC (Windows or Mac) with the Unity 3D game engine installed.
You don't need a superpowerful rig. While Unity can be a beast that can render complex scenes and Oculus has published recommended specifications for PC hardware, you can get by with less. Even a laptop will do for the projects in this book.
To get Unity, go to https://unity3d.com/get-unity/, select the version that you want, click on Download Installer, and continue following the instructions. The free Personal Edition version of Unity is fine.
We can also optionally use the Blender open source project for 3D modeling. This book isn't about Blender, but we'll use it if you want. To get Blender, go to http://www.blender.org/download/ and follow the instructions for your platform.
Access to a virtual reality head-mounted display (HMD) is recommended in order to try out your builds and get first-hand experience of the projects developed in this book. It's entirely possible to build and run all the projects on a desktop monitor, but where's the fun in that? This book addresses the details of both Google Cardboard and Oculus Rift.
Google Cardboard is an example of Mobile VR, where you use your smartphone to run the VR apps. If you have an Android smartphone, you'll also need the Android development tools from Google. If you have an iOS device, you'll also need the Xcode development tools (and license) from Apple. The details are covered in Chapter 3, VR Build and Run.
Oculus Rift is an example of Desktop VR. Presently, Unity has built-in support for the Rift. However, if you have a different head-mounted display (HMD), you may also need to download a Unity interface package from the device manufacturer. Again, the details are covered in Chapter 3, VR Build and Run.
This should just about do it—a PC, the Unity software, a HMD, and we're good to go!
If you are interested in virtual reality, want to learn how it works, or want to create your own VR experiences, this book is for you. Whether you're a nonprogrammer and are unfamiliar with 3D computer graphics, or experienced in both but new to virtual reality, you will benefit from this book. It is not a fresh start with Unity, but you do not need to be an expert either. Nevertheless, if you're new to Unity, you can pick up this book as long as you realize that you'll need to adapt to the pace of the book.
Game developers may already be familiar with the concepts in the book, reapplied to the VR projects while learning many other ideas specific to VR. Mobile and 2D game designers who already know how to use Unity will discover another dimension! Engineers and 3D designers may understand many of the 3D concepts, but they may learn to use the game engine for VR. Application developers may appreciate the potential nongaming uses of VR and want to learn the tools that can make this happen.
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Modify the AvatarMultiplayer.cs
script."
A block of code is set as follows:
using UnityEngine; using System.Collections; public class RandomPosition : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { } }
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
public class ButtonExecute : MonoBehaviour { public float timeToSelect = 2.0f; private float countDown; private GameObject currentButton; private clicker = new Clicker ();
Any command-line input or output is written as follows:
moveDirection *= moveDirection * velocity * Time.deltaTime; transform.position += transform.position + moveDirection;
New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Click on the Create a Room button."
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail <[email protected]>
, and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from http://www.packtpub.com/sites/default/files/downloads/8556OS_ColorImages.pdf.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]>
with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at <[email protected]>
, and we will do our best to address the problem.