Search Unity

Get rotation from Motion Controllers?

Discussion in 'VR' started by COLiTRON, Sep 17, 2018.

  1. COLiTRON

    COLiTRON

    Joined:
    Dec 20, 2017
    Posts:
    8
    Hey folks, I have a question about scripting for the Motion Controllers:
    I would like to write a script that gets the 6DoF grip pose rotation from my left Motion Controller (Specifically the Y rotation) and applies that rotation to a game object. I've written scripts that do this for game objects, but I'm having a tough time figuring out where to begin when it comes to making an object to get it's rotation from a Motion Controller.

    As an example of what I'm trying to do, here's a script I wrote that makes a game object match the Y rotation of another game object:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class GetYRotation : MonoBehaviour {
    6.  
    7. public GameObject YParent;
    8.  
    9. void Update () {
    10.     transform.localEulerAngles = new Vector3(0.0f, YParent.transform.localEulerAngles.y, 0.0f);
    11.  
    12. }
    13. }
    So basically, I'd like to write a script that does that, but instead of getting the rotation from a game object, it gets the rotation from Motion Controller's rotation. I know you can get the Motion Controller rotation from XR.InputTracking.GetLocalRotation, but I'm having a tough time scripting for anything XR.WSA.Input related so far. (Yes, I'm still new to this.) I'm sure you experienced devs will get a laugh from this-

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.XR.WSA.Input;
    5.  
    6. namespace HoloToolkit.Unity.InputModule
    7.  
    8. public class GetMotionControRotation : MonoBehaviour {
    9.  
    10. void Update () {
    11.     transform.localEulerAngles = InputTracking.GetLocalRotation(XRNode.LeftHand);
    12.  
    13. }
    14. }
    That just created a bunch of errors. Am I completely on the wrong track here? If you have any suggestions, or if you know of any good tutorials on getting started with scripting for XR.WSA.Input related things, I'd really appreciate it.

    Thanks!
     
  2. JasonCostanza

    JasonCostanza

    Unity Technologies

    Joined:
    May 23, 2017
    Posts:
    404
  3. COLiTRON

    COLiTRON

    Joined:
    Dec 20, 2017
    Posts:
    8
    Thanks Jason! I'll give those a shot. Also, I recently realized that I've been using Visual Studio without the right configurations setup. I must have glazed over that when I installed the HoloToolKit months ago. I've sorta been working with one hand tied behind my back this whole time. Oops.
     
    JasonCostanza likes this.
  4. JasonCostanza

    JasonCostanza

    Unity Technologies

    Joined:
    May 23, 2017
    Posts:
    404
    But you could go down in history as the man who conquered MR Input one-handed!

    Anyways, glad it might have opened up a path forward. Let us know if you have any other questions!
     
  5. Don-L727

    Don-L727

    Joined:
    Aug 6, 2014
    Posts:
    38
    COLiTRON, that ever work out for you? I also got a WMR headset and became interested in Unity3d. But understanding the controller setup was difficult to get into.