This blog post documents some simple steps to get an initial Virtual Reality (VR) application built in Unity 5 to display and be controlled via the Oculus Rift DK2 Head Mounted Display (HMD) using Windows 10, Unity 5.2 and Oculus Runtime 0.7.
Initial Unity Project and Scene
- Create a new empty project. Note it already includes a “Main Camera” and a “Directional Light” to light the scene.
- Insert a simple solid ground plane to prevent your character dropping down. Use GameObject -> 3D Object -> Plane, for example, and make the object be located just below Y (something like -0.1) and have a decent extent in the X and Z directions. This will be able to be removed later when you have real content and terrain in your scene.
- Import the Environment Water via Assets -> Import Package -> Environment. Deselect the preticked assets using “None” and only select the “Water” assets and then “Import”.
- Under Assets -> Standard Assets -> Environment -> Water -> Water -> Prefabs, drop the WaterProDaytime prefab into the Unity hierarchy panel to include it in the scene. Set its Y position at 0 and scale it up in the X and Z directions.
- Under Assets -> Standard Assets -> Environment -> Water -> Water -> Prefabs, drop the WaterProNighttime prefab into the Unity hierarchy panel to include it in the scene. Also set its Y position at 0 and scale it up in the X and Z directions. Rotate this 180 degrees in the X direction. This has the effect of giving a water surface seen from underneath.
- Import the Characters Package via Assets -> Import Package -> Characters and select “All” and then “Import”.
- Then you will have available a Unity character “Ethan” in the standard Assets at Assets -> Standard Assets -> Characters -> ThirdPersonCharacter -> Prefabs folder which can be included in a Unity scene.
- The “Main Camera” already in the scene can now be dragged inside the “ThirdPersonController” hierarchy and it is then attached to the motion of the character.
- Now save the scene and save the project and you are ready to create the Unity builds for a range of platforms.
- For the Oculus Rift and VR, use File -> Build Settings… choose the PC/Mac/Linux Standalone and use “Player Settings” button to set the “Virtual Reality Supported” tickbox on. “Stereoscopic Rendering” should NOT be ticked. Then build the executable.
- You can also preview the scene in your VR HMD, if it is turned on, using the game mode preview within the Unity editor.
Unity Ethan and Other Avatar Models and Cameras
See notes in the Assets -> Standard Assets -> Characters -> ThirdPersonCharacter folder on how to replace the Unity Standard Assets Ethan character’s 3D model with other FBX avatar rigged meshes that are in a suitable format. The following blog posts also covers this process.
- http://answers.unity3d.com/questions/914933/replace-the-ethan-character-in-unity-50.html
- https://blog.inf.ed.ac.uk/atate/2015/09/21/unity3d-characters/
The attached avatar camera can also be made more sophisticated than the default Unity project “Main Camera”. An example of this is the flexible “UnityChan” character camera scripts included in Fumikazu Iseki’s OpenSim OAR Converter to Unity converter, in the “Unity3D” folder. For more details see…
OpenVCE OAR Converted to Unity and in VR
Using Fumikazu Iseki’s OpenSim OAR to Collada DAE and Unity Assets “OAR Converter” – see this blog post – the OpenVCE region in OpenSim was imported to Unity along with the Ethan character and Water layers as described above. When using the Unity editor game preview with the Oculus Rift DK2 turned on, the VR HMD display and head movement for camera direction all work fine.
Connecting the Unity Main Camera to the Oculus VR
“Oculus Utilities for Unity 5” (version 0.1.0 beta as at 10-Sep-2015) are available to add to your project…
- Unity VR Overview
- Utilities for Unity Developer Guide
- The “Oculus Utilities for Unity 5” package is available for download at the Oculus Developer site (requires login): https://developer.oculus.com/downloads/
If you are using the OAR Converter test avatar, UnityChan, in order to connect the VR HMD to the UnityChan camera, the advice from Fumikazu Iseki is…
Prior to build for VR applications, add OVR/Scripts/OVRCameraRig.cs
and OVR/Scripts/OVRManager.cs scripts to the UnityChan_Camera via
the “Add Components” button and using the “Script” type.
With the OpenSim OpenVCE OAR content converted and imported to Unity this is how the scene looks and works on the Oculus VR HMD both in editor preview mode and after a PC targeted build with “Virtual Reality Supported” ticked in the Build Settings -> Player Settings …
Experiments with Unity UI Elements
The inbuilt UI elements were used to add drop down selections, buttons and floating text to which scripted event triggers can be added.
- Unity Bootcamp Videos –
Events and UI elements,
Event System and VR Elements - Some ideas on putting 2D User Interface elements into the 3D space for use with a VR HMD…
http://coherent-labs.com/blog/modern-game-ui-with-the-oculus-rift-part-2/ - Ensuring the Mouse Pointer shows on the Oculus in VR… http://unitygirldev.blogspot.co.uk/2015/01/unity-script-oculus-3d-pointer.html