- Home /
Rotate object with head movement of cardboard keeping object in focus.
I am developing an android app using unity 3D, where I am trying to keep object in focus and on head movement the object should move relatively to camera. As the object moves in google cardboard demo app (exhibit , mask demo) Object rotates on its axis, when we rotate our head.
I tried with the scripts FocusObject.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FocusObject : MonoBehaviour {
private GvrHead head;
private Vector3 offset;
public GameObject scrimshaw;
// Use this for initialization
void Start () {
head = Camera.main.GetComponent<StereoController>().Head;
scrimshaw = GameObject.FindGameObjectWithTag ("monkey");
}
// 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;
}
}
And I also tried keeping my object inside hierarchy of camera, creating a GameObject and then keeping outside of main camera, But nothing worked.
screen-shot-2017-02-06-at-23423-pm.png
(232.2 kB)
screen-shot-2017-02-06-at-55408-pm.png
(24.3 kB)
Comment