Convert GetAxis (mouse) to VR head movement

Hi! I’m making my first VR prototype. It’s just a first person dynamic crosshair test. As the newbie I am, I made it all work… on PC, using a mouse to control the view, without any VR integration at the beginning. The question would be: is there any “easy” way to just turn the values I get with Input.GetAxis (“Mouse X”) or (“Mouse Y”) into the head tracking values used for VR? I’ve found that there are some scripts which allow you to easily implement VR camera, input, interactive objects, etc. if you use them from the start. But now that everything is almost ready, I wonder if there’s an equivalent function to Input.GetAxis for VR tracking.

This is the (ultra basic) script I use to move the camera with the mouse:

using UnityEngine;
using System.Collections;

public class CamMovement : MonoBehaviour
{
public float speedH = 2.0f;
public float speedV = 2.0f;

private float yaw = 0.0f;
private float pitch = 0.0f;

void Update () 
{
	yaw += speedH * Input.GetAxis("Mouse X");
	pitch -= speedV * Input.GetAxis("Mouse Y");

	transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
}

}

And this is another thing I’m doing on another script: filling a bar following the vertical mouse movement under specific circumstances:

void Fill () 
{
	if (
		(Input.GetAxis ("Mouse X") < horMargin) &&
		(Input.GetAxis ("Mouse X") > -horMargin))	
	{
		filler += fillRate * Input.GetAxis ("Mouse Y");
		filler = Mathf.Clamp (filler, -10, 0);
	}
}

}

Any possible way to make this all VR tracking-ready without loads of adapting work? Thank you very much.

Just realized I could tell how I eventually solved this. The first basic point was making the camera work when using the VR headset. Recent Unity versions seem to make it easy: just put your camera within a parent game object and attach your script to this parent object. It worked perfectly.

But my real problem was that I had another input that depended on the GetAxis input (a bar that was supposed to fill following the player’s gaze), and that wasn’t working at all. Since that probably wasn’t a proper input for VR, I tried using the game object’s rotation to “simulate” that gaze. But even when the “VR camera” takes control of the movement you set for your original camera (now scripted on the parent game object), it didn’t seem to be really taking into account any transform.

Well, after all this frustrating process (I know there are easier ways to have done it from the start…), the solution was not that difficult: using InputTracking.GetLocalRotation(VRNode.Head).eulerAngles.x (as I wanted to track vertical head movement).

Yes, I know it’s not that hard of an issue, but for me it was difficult to solve properly and, since nobody fed this thread, I just wanted to decorate it with a closure. Thanks!