Saturday, January 17, 2015

Unity Script: Oculus 3d Pointer (1 of 3)

One of the biggest obstacles to developing for the Oculus is simulating mouse. This post will take us through the first of three basic steps to get Oculus mouse integration working. We'll create a 3d mouse-object that follows the mouse-movement. Next time we'll add click-integration using triggers in post 2 and we'll finish with click-integration for Coherent UI web views.

____________________________________________________________

Myriad Limitations:

There are a couple of very good reasons why we can't just use the mouse the normal Unity way.

Oculus won't display the windows mouse-cursor

You can't hijack/alter the windows mouse-cursor at-all easily

The windows mouse-cursor aims wrong through the Oculus distortion -even if you can see it-

A Unity-Object 3D Pointer

That's right. We're gonna take a Unity asset and turn it into our pointer with a few simple scripting tricks. We'll start with your player-camera and your pointer. I use a red sphere-object as default but you can use whatever works for you.

Create your object

Parent object under Right Eye Anchor

this means it'll stick to the front of the head when you move

Transform thusly

It should look something like this with the pointer selected

Finally, add this script that will link the pointer-movement to your physical mouse movement.