I'm new to Unity (and VR) and trying to create a small example in Google Cardboard, where I have a model that rotates when the user turns his head - similar to the mask demonstration in the Google Cardboard application. Therefore, when the user looks up, the model rotates up, when viewing left, the model rotates left, etc.
My scene currently has CardboardMain and my 3D model. I attached the Cardboard head script to my model, which now rotates correctly with a head movement. None if the subject remains in front of the camera.
To achieve this functionality, I created a script that I linked 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;
void Start () {
head = Camera.main.GetComponent<StereoController>().Head;
scrimshaw = GameObject.FindGameObjectWithTag ("Scrimshaw");
}
void LateUpdate () {
offset = head.Gaze.direction + head.transform.position;
scrimshaw.transform.position = scrimshaw.transform.position + offset;
}
}
. , transform.position 3, . ?
transform.LookAt (target) Main Camera, . , , .