I am new to Unity (and VR) and am trying to set up a small example in Google Cardboard where I have a model that turns when the user turns her head - similar to the mask demo in the Google Cardboard App. So when the user looks up, the model rotates up, when looking left, the model rotates left etc.
My scene currently has a CardboardMain and my 3D model. I have attached the Cardboard Head script to my model, which now rotates correctly with the head movement. What is missing is having the object remain in front of the camera.
In order to achieve that functionality, I created a script which I attached to my 3D Model. The script looks like this:
using UnityEngine;
using System.Collections;
public class lookAtMe : MonoBehaviour {
private CardboardHead head;
private Vector3 offset;
public GameObject scrimshaw;
// Use this for initialization
void Start () {
head = Camera.main.GetComponent<StereoController>().Head;
scrimshaw = GameObject.FindGameObjectWithTag ("Scrimshaw");
}
// Update at end of frame
void LateUpdate () {
// head.transform.position = the positon of the head on the plane
// head.Gaze.direction = positon of where the head is looking
offset = head.Gaze.direction + head.transform.position;
scrimshaw.transform.position = scrimshaw.transform.position + offset;
}
}
However, the position of my model does not change. I was under the impression that if I provide transform.position
with a new vector 3 it will move the object accordingly. How else could it be done?
I did try applying transform.LookAt (target)
at the Main Camera instance, setting the target to the model. While this method does work, it is way to jerky to be usable.