-
Notifications
You must be signed in to change notification settings - Fork 1
Virtual Reality Workshop
These notes are intended to be used by the instructor of a short, hands-on course for VR development using Unity 3D game engine. The goals of this course are to introduce students to VR hardware and software currently in use (Oculus Rift, Leap Motion, Unity 3D) and give them the opportunity to see and use them firsthand.
This is a workshop designed to introduce students to the basic concepts/software behind virtual reality development at OU Libraries. We will be discussing the hardware and software used to-date, and will guide students through the steps necessary to create a simple VR app using Unity 3D software.
- Explain the hardware and software used in VR Development at OU.
- Create a simple game using physics and input controls in order to demonstrate knowledge of Unity workflows that drive VR development.
-
Oculus
- Consumer Model (imminent)
- Only provides support for Windows
-
Vive
- HTC and the Valve Corporation
-
Morpheus
- Sony
- Unity & MonoDevelop/Visual Studio
- Free (for personal edition), what we currently use.
- Unreal
- Free (for personal edition), not implemented here yet.
When we talk about VR development, we're really talking about game development. Oculus and other VR technologies are born from and driven by the world of video games, so we use video game development tools to create VR experiences. The most important of these is Unity, which will be a large focus in the workshop today.
Unity3D is a professional-grade game development platform. The Enterprise version comes with a bit more on the corporate support side, but the free edition has almost all of the features and access to a great community that can answer most questions. It can create everything from a simple 2D game like Snake all the way up to complex, multiplayer VR experiences.
- Open up Unity
- Select "3D," and do not import any asset packages for now
- Name the project, i.e. "NewProject"
- Create Project!
This brings us to a new, empty project. We are now viewing the Unity Editor. This is Unity's interface for crafting and manipulating objects and scenes:
Components to highlight:
- Hierarchy
- This is where GameObjects, Lights, Cameras are arranged. You can click on an item here to select it and view its components in the Inspector.
- Scene View
- This is the "behind-the-scenes" view of the game area. You can directly select and manipulate objects here.
- Inspector
- This is where you can view the components attached to different objects, including physics, effects, scripts, etc. (more on this in a minute)
- Project Pane
- This is where all of your assets will be viewed and accessible
- Console
- This will be where you can see errors in your scripts and messages you deliberately send - very useful for debugging
- Game View
- This is what the game will actually look like. If you hit the "play" button, this is where you will see the action happening.
Our "empty" scene actually begins with two items in the Hierarchy by default. One is a Directional Light, and one is the Main Camera. These are two special kinds of objects that Unity has. To understand why they're special, though, we're going to add a third object to our scene (a primitive sphere).
To create a sphere: GameObject > 3D Object > Sphere
This now appears in the Hierarchy and in the Scene View.
In the Hierarchy, select the Directional Light and then use the rotation controls in Scene View to show how the Directional Light works (like the sun, it comes from just one direction and objects can cast shadows, including our Sphere). Select the Main Camera to show how it is our view into the scene.
Before we move on, add a primitive Cube.
Before we get too far, let's practice importing assets/packages. We'll just do a standard package to start, but you can import packages that you download from various places (i.e. Oculus, Leap Motion).
Assets > Import Package > Environment
Notice how these now appear in the Project pane. You can now drag and drop these into the scene or hierarchy. Let's add GrassHillAlbedo to the Cube and CliffAlbedoSpecular to the Sphere. Applying these 2D Textures to 3D objects will automatically create materials for them.
Materials : Describes the physical-qualities appearance of an object (shiny, reflective, rough, etc.). Can contain multiple Textures. Are applied to objects.
Textures : 2D images that are applied to materials, which are in turn applied to objects. Provide color information, etc.
Select Cube in the Hierarchy. In the Inspector, note the list of Components that has appeared. Components are the things that describe what an object is and how it behaves. There should be five components on the cube by default.
- Transform
- Describes the position, rotation, and scale of an object. Without this, there is no object.
- Mesh Filter
- Is the idea of an object's shape. It's like a blueprint for an object.
- Box Collider
- If we have physics, this is the thing that tells us where an object detects collisions. This one is in the shape of a box.
- Mesh Renderer
- This is what renders - obviously - the material of an object (how it looks).
- Default-Material
- Plain white material that comes as a default on primitive objects.
Let's alter the Transform of the Cube first. Let's set the position to (0,0,0), the rotation to (0,0,0), and the scale to (8,1,1).
Alter the Transform of the Sphere to (0,2,0)
Add RigidBody to both: Add Component > Physics > RigidBody
Freeze Rotation and Location of Cube, remove Gravity.
We want to move the ball around when we get inputs. Here's a quick way to do that:
using UnityEngine;
using System.Collections;
public class BallMovement : MonoBehaviour {
public float speed;
// Update is called once per frame
void Update () {
if (Input.GetKey ("d")) {
this.GetComponent<Rigidbody>().AddForce(Camera.main.transform.right * speed);
}
if (Input.GetKey ("a")) {
this.GetComponent<Rigidbody>().AddForce(-Camera.main.transform.right * speed);
}
}
}
Now we want to add a "reset" when the ball falls off. Add these lines:
if (this.transform.position.y < -4) {
this.transform.localPosition = new Vector3(0f,2f,0f);
}
How about a jump feature? The C# script we've written should look like this:
using UnityEngine;
using System.Collections;
public class BallMovement : MonoBehaviour {
public float speed;
public float jump = 15f;
private bool grounded = false;
// Update is called once per frame
void Update () {
if (Input.GetKey ("d")) {
this.GetComponent<Rigidbody>().AddForce(Camera.main.transform.right * speed);
}
if (Input.GetKey ("a")) {
this.GetComponent<Rigidbody>().AddForce(-Camera.main.transform.right * speed);
}
if (Input.GetKeyDown ("space") && (grounded == true)) {
this.GetComponent<Rigidbody>().AddForce(Camera.main.transform.up * jump * 100);
grounded = false;
}
if (this.transform.position.y < -4) {
this.transform.localPosition = new Vector3(0f,2f,0f);
}
}
void OnCollisionEnter (Collision hit)
{
grounded = true;
}
}
What separates VR from a regular game? Essentially, the sort of camera we're using. This is something we can download from Oculus, but here's a quick Dropbox link to the stuff we need.
Assets > Import Package > Custom Package...
Then import "OculusUtilities.unitypackage" to get a whole bunch of Oculus assets added to the scene.
Remove the Main Camera.
Add the OVRPlayerController Prefab.
Uncheck "OVR Debug Info" to deactivate it.
Now we've got VR.
Once we've built our game, we want to be able to play it as a standalone app or executable. To do that:
File > Build Settings...
This will give us a window with options for exporting to all kinds of systems. The easiest for us, though, is "PC, Mac, & Linux Standalone." From there, we can mess with a few options, and then press "Build" to export our game to play outside of Unity.
Visit us on the EDGE website!

