Hello everyone.

We have decided to phase out the Mixed Reality Forums over the next few months in favor of other ways to connect with us.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

The plan between now and the beginning of May is to clean up old, unanswered questions that are no longer relevant. The forums will remain open and usable.

On May 1st we will be locking the forums to new posts and replies. They will remain available for another three months for the purposes of searching them, and then they will be closed altogether on August 1st.

So, where does that leave our awesome community to ask questions? Well, there are a few places we want to engage with you. For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality. If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers. And always feel free to hit us up on Twitter @MxdRealityDev.

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.