Search code examples
unity-game-enginemrtkwindows-mixed-reality

MRTK Unity getting WMR Controller position and rotation


I would like to know about how getting WMR controller position and rotation with MRTK on Unity.

Scenario: Object picked up by one of the controller(Left/Right), and object will follow the position & rotation of the controller.

Current State

I can trigger the grab/pick event and validate the handedness (R/L). This is sample of my basic code:

public class WeaponControl : MonoBehaviour, IMixedRealityInputHandler
{
    private Handedness pickedHand;
    private bool isPickedUp = false;

    public void OnInputDown(InputEventData eventData)
    {
        if(eventData.InputSource.SourceType == InputSourceType.Controller && isPickedUp == false)
        {
            Debug.Log("Left Hand");
            isPickedUp = true;
            pickedHand = eventData.Handedness;
        }
    }

    public void OnInputUp(InputEventData eventData)
    {
        //throw new System.NotImplementedException();
    }

    /// Method on tracking controller below
    ///

}

Goal

Tracking position and rotation of selected controller


Solution

  • Based on your description, I recommend using the Solver provided by MRTKv2 to implement the object following controller instead of manually obtaining the Position and Rotation of the controller. In the solver system, you can set the reference object in the SolverHandler component, and choose different solver according to different needs. More information please see: https://microsoft.github.io/MixedRealityToolkit-Unity/Documentation/README_Solver.html