Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to do Head based steering

Discussion in 'AR/VR (XR) Discussion' started by ToolofNA, Mar 16, 2015.

  1. ToolofNA

    ToolofNA

    Joined:
    Mar 26, 2014
    Posts:
    2
    Hi does anyone have any info on how to get head based steering working for google cardboard.
    Moving the player in the direction you look (up down left and right)

    I have searched for weeks now and can't find anything other than what google mentions in their plug in reference page. They mention a use case for head based steering, but I have only been able to get
    it working moving the player left and right but not up and down. I want to use it to steer a flight sim.

    Any help or advice would be huge.

    Clay


    Below is the info I got from Googles Dev site.


    CardboardHead.cs

    Attach this script to any game object that should match the user's head motion. By default, it continuously updates the local transform to the HeadView of the Cardboard object. A target object may be specified to provide an alternate reference frame for the rotation.

    This script will typically be attached to directly to a Camera object, or to its parent if you need to offset the camera from the origin of rotation. Alternatively it can be inserted as a child of the Camera and parent of the CardboardEye camera. Do this if you already have steering logic driving the mono Camera and wish to have the user's head motion be relative to that. Note that in the latter setup, head tracking is visible only when VR Mode is enabled.

    Properties
    Transform target [defaultnull]

    The user's head rotation will be applied in this object's reference frame instead of the head object's parent. A good use case is for head-based steering. Normally, turning the parent object (i.e. the body or vehicle) towards the direction the user is looking would carry the head along with it, thus creating a positive feedback loop. Use an external target object as a fixed point of reference for the direction the user is looking.
     
  2. dolims

    dolims

    Joined:
    Sep 13, 2014
    Posts:
    61
    That target property is for doing third-person steering, where you see the object (car, plane, spaceship) in front of you as you steer it. If you want to do first-person steering, it's much simpler than that. Try something like this:

    public float speed = /* some number */;

    private CardboardHead head;

    void Start()
    {
    head = // find the CardboardHead
    // example:
    // head = Camera.main.GetComponent<StereoController>().Head;
    // or, make the variable public and use drag-and-drop in the Editor
    }

    void Update()
    {
    transform.position += speed * head.Gaze.direction;
    }

    [edit]
    A good place to attach this script would be the CardboardMain object, if you are using that prefab. One important point: this doesn't rotate the object being steered, so it won't work if there's a model attached. But, that's why it's simpler!
     
    Last edited: Mar 17, 2015
    ToolofNA, KidNova and Daoqi like this.