Search Unity

Snap Turn, new XR features Help

Discussion in 'AR/VR (XR) Discussion' started by Rafael-Barbosa, May 11, 2018.

  1. Rafael-Barbosa

    Rafael-Barbosa

    Joined:
    Apr 14, 2013
    Posts:
    288
    Hello all,
    It's been a while since I last posted here. I've been working on a new project using unity's new XR Input system. Currently, I have a player setup with the Tracked Pose Driver component, everything is working correctly but I have no clue as to how to implement my Snap Turn Mechanic. If I rotate the camera itself, it won't be able to overwrite the HMD's rotation, so I had to rotate the parent object. The issue with that, is that the parent object is placed on the center of the play space, no on the center of the HMD. So if I turn it, the player actually get's moved a bit since he is offset from the perfect center.
    Keep in mind that I am unable to move nor rotate the Head object as it's position and rotation are being updated by Tracked Pose Driver which receives input from the HMD.

    The first gif illustrates what is happening when I turn my player:



    The second one illustrates what I want to achieve:



    Any ideas ?
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,411
  3. Rafael-Barbosa

    Rafael-Barbosa

    Joined:
    Apr 14, 2013
    Posts:
    288

    Awesome idea mate! It worked perfectly.

    For anyone who also has this issue, the fix was to use the RotateAround feature,
    here is a code snipped of the fix:
    Code (CSharp):
    1. public Transform Headset;
    2.  
    3. void Update(){
    4.  
    5.     if(Input.GetButton("Rotate_Left")){
    6.             PlayArea.RotateAround(Headset.position, Vector3.up, -45);
    7.  
    8.         }
    9.     }
    10. }
     
    ROBYER1 likes this.
  4. Thomukas1

    Thomukas1

    Joined:
    Sep 29, 2014
    Posts:
    31
    Thank you so much Rafael! I had the same issue and with your simple snipper i was able to make it work immediately. Genius solution!
     
  5. colinleet

    colinleet

    Joined:
    Nov 20, 2019
    Posts:
    189
    There is a special command to get this done right:

    // Found this beauty in the newest release of the interaction Toolkit

    system.xrRig.RotateAroundCameraUsingRigUp(turnAmount);

    The newest release of the Interaction Toolkit also has a bunch of new player rotating scripts e.g. snap/smooth snap/continuous... All work well and are ready to use.
     
    ROBYER1 likes this.