Keep the subject “still” in front of the camera (Google Cardboard + Unity)

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;

    // 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;
    }
}

. , transform.position 3, . ?

transform.LookAt (target) Main Camera, . , , .

+4
2

no script. - CardboardMain, . .

CardboardHead script , .

+2

, - , . , .

+1

Source: https://habr.com/ru/post/1619960/


All Articles