Thursday, April 17, 2014

Unity Pro 4: Using the OVRCameraController prefab

In a previous post, I looked at getting started with Unity Pro 4 using the OVRPlayerController prefab included with the Oculus Unity Pro 4 Integration package. In this post, I want to look at using the OVRCameraController prefab with a custom player controller. Getting started requires the same basic setup as using the OvrPlayerController prefab: creating a scene and then adding the Oculus integration package into the project's assets. To save time, I just used the same scene I created for the last post, a beach with palm trees, for this test as well.  As I plan to use the Unity first person player controller as my character controller, I also added the Unity Character Controller standard assets to my project.


The OVRCameraController prefab included in the Oculus Integration package contains the stereo cameras used for Rift integration. To use this prefab, you need to attach it to a moving object in your scene. For the moving object in my scene I used a simple player controller. To create the player controller, I first added an empty GameObject (GameObject > Create Empty) and to make it easier to keep track of,  I renamed it "Player".  I then  added a Character Controller (Component >  Physics > Character Controller) to my Player object and attached the first person player controller (FPSInputController.js) and mouse look (MouseLook.cs) scripts found in the Character Controller standard assets to the Player. After I positioned my Player in the scene so that it wasn't colliding with the plane, this is what it looked like expanded in the Inspector.


I then grabbed the OVRCameraController prefab from Assets > Prefabs in the Project menu, and simply added it as a child of the Player.


And gave it a test run.


With my Rift connected and active, the scene was displayed with left and right images in the Rift’s oval views. If my Rift was not connected and active, the left and right views would simply be rectangles.

I was able to move the character around but MouseLook did not work. For that to function, I needed to make a few adjustments to the scripts. I made the following changes:
  1. In the Inspector for OVRCameraController, I set Follow Orientation to OVRCameraController
  2. I then edited the FPSInputController.js script so that it would recognize  OVRCameraController. 
    • At the top, I added a new public variable called ovrCamera of type GameObject:  public var ovrCamera : GameObject; 
    • I changed this line:
       motor.inputMoveDirection = transform.rotation * directionVector; 
      to this, so that the transform used would be from the object stored in ovrCamera:
      motor.inputMoveDirection = ovrCamera.transform.rotation * directionVector; 
    • And in the Player Inspector for the First Person Controller, I set the value of ovrCamera to CameraRight so that the transform used would be that of CameraRight. 
  3. In the Player Inspector for the MouseLook script, I set the Axes for my testing environment. I was testing with a Rift attached, so I set Axes to MouseX as I would be using the Rift to look in all directions. If testing without a Rift, I would have set it to MouseXAndY so that I could use the mouse to look in all directions. 
With those changes complete, I gave it another a test run.  I was able to navigate the scene and turn with the mouse.

After testing out both the OVRPlayerController and the Unity Standard Player controller with the Rift, there were two things that I noticed right away. First, the default player speeds for OVRPlayerController are much slower than those in the Standard Unity Player controller. Player speed plays an important part in how comfortable the VR environment is, and the faster character speed was bit uncomfortable for me. The Oculus Best Practice guide lists a walking rate of 1.4 m/s and a jogging rate of 3 m/s as most comfortable.

Second, it was clear I needed to set the default player eye height to something closer to my own height for it to be a comfortable experience. In a future post I will take a look at how to set the default player eye height.


1 comment:

  1. Hi did you solve the eye height problem? im stuck on that

    ReplyDelete

Note: Only a member of this blog may post a comment.