SONY

menu
Search button in the site

Open the search area of the siteく

Track the users eye position and apply to a 3D object in Unity

This page describes how to track the users eye position and apply to a 3D object to follow the user’s movements on the Spatial Reality Display (SR Display) in Unity.
You can also try it with the sample included in the Plugin.

  1. Setup your SR Display, if not, see: Setup SR DisplaySetup SR Display Runtime.
  2. Set up your Unity project installed SRDisplay UnityPlugin, if not, see: Setup for Unity.
  1. Put SRDisplayManager Prefab in your scene Hierarchy with reference to here.
    SRDisplayBox Prefab in Assets / SRDisplayUnityPlugin / Runtime / Prefabs is also placed here.

  2. Create a character using 3D objects, adjusting them to fit within SRDisplayManager Prefab.

  3. Add C# script. Open Script file you have added and edit it as follows.
    Make sure that the file name and class name of the added script are the same.

    
            using UnityEngine;
            public class LookAtYou : MonoBehaviour
            {
                public GameObject LookAtTarget;
                void Update()
                {
                    if (LookAtTarget == null)
                    {
                        return;
                    }
                    var forwardVec = this.transform.position - LookAtTarget.transform.position;
                    this.transform.rotation = Quaternion.LookRotation(forwardVec, Vector3.up);
                }
            }
                  
  4. Attach the C# script you have created to the face part of object.
    Specify WatcherAnothor to be a child object of SRDisplayManager in “Look At Target”. WatcherAnothor shows the user's head position at runtime. (Read more here.)

  5. Let's run the application. The character will turn its head to match the position of your face.