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:
- In the Inspector for OVRCameraController, I set Follow Orientation to OVRCameraController.
- 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.
With those changes complete, I gave it another a test run. I was able to navigate the scene and turn with the mouse.
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.