Get rotation from Motion Controllers?

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 the Motion Controllers.

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:

`using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GetYRotation : MonoBehaviour {

public GameObject YParent;

void Update () {
    transform.localEulerAngles = new Vector3(0.0f, YParent.transform.localEulerAngles.y, 0.0f);

}

}`

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-

Initially, I hoped that a script like this would at least be a start:

`using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.WSA.Input;

namespace HoloToolkit.Unity.InputModule

public class GetMotionControRotation : MonoBehaviour {

void Update () {
    transform.localEulerAngles = InputTracking.GetLocalRotation(XRNode.LeftHand);

}

}
`

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!

**- Colin **(Just some weird guy trying to build some weird worlds.)

Best Answer

  • Accepted Answer

    Annnnnd after all that banging my head against the wall... Turns out theres a component in Unity that will apply the position and/or the rotation data of the motion controllers to any game object. Well, that solves that.

    **- Colin **(Just some weird guy trying to build some weird worlds.)

Answers

  • Accepted Answer

    Annnnnd after all that banging my head against the wall... Turns out theres a component in Unity that will apply the position and/or the rotation data of the motion controllers to any game object. Well, that solves that.

    **- Colin **(Just some weird guy trying to build some weird worlds.)

Sign In or Register to comment.