Home Forums Unity SDK Move GameObject with Gaze Point

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #22174
    Varun Ramakrishnan
    Participant

    I am currently trying to move an object with the user’s gaze point but am having trouble converting the gaze point to a world space position.

    My scene setup is:
    – An eye image on a canvas that follows the user’s gaze (so that the user can see what they’re looking at)
    – A cube on a plane that the user is supposed to move with their eyes.

    The objective is for the user to move the cube with their eye after looking at it. I change the cube’s material color once it HasGazeFocus and that works without any issues so I know that the GazeAware component and Tobii are working correctly.

        void Update()
        {
            transform.position = Camera.main.ViewportToScreenPoint(Tobii.Gaming.TobiiAPI.GetGazePoint().Viewport);
        }
    

    The canvas image has the above in a script attached to it and moves correctly but the cube is always at the same position.

    I have tried using GetGazePoint().Screen followed by camera.ScreenToWorldPoint as well as ‘GetGazePoint().Viewportfollowed bycamera.ViewportToWorldPoint` but neither of them seem to change the cube’s position.

    Right now I’m moving it in 2D along the XY plane so I fix the z-coordinate to a constant.

    Any pointers on how I could make the cube move with the eye would be appreciated.

    #22247
    Grant [Tobii]
    Keymaster

    Hi @vramakrishnan, did you check the values of the gaze point as reported in the sample script we produced @

    Scripting API

    using Unity.Engine;
    using Tobii.Gaming;
    
    public class ExampleClass : MonoBehaviour
    {
        void Update()
        {
            GazePoint gazePoint = TobiiAPI.GetGazePoint();
            if (gazePoint.IsRecent()) // Use IsValid property instead to process old but valid data
            {
                // Note: Values can be negative if the user looks outside the game view.
                print("Gaze point on Screen (X,Y): " + gazePoint.Screen.x + ", " + gazePoint.Screen.y);
            }
        }
    }

    It would be an idea to see what values are being produced to see how to convert them to your own desired coordinate system.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.