2

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

Adityo Setyonugroho
  • 877
  • 1
  • 11
  • 29

1 Answers1

1

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

Hernando - MSFT
  • 2,895
  • 1
  • 5
  • 11
  • Isn't there any alternative from using solvers to get the position and rotation of the controller (and that is not deprecated) ? – Entretoize Feb 13 '20 at 09:06
  • that is not a good answer. I work at MS, I am very familiar with the MRTK, and being able to get the position of the controllers should be dead simple and not require the MRTK or any other heavy-weight harness. – eric frazer Apr 26 '20 at 05:54
  • I am using the HandConstraint solver with solver handler tracked target type as Controller Ray. As per documentation it should support both controller and hand. But for some reason the controller is not tracked until I once use my hands and then I use the controller. How do I fix this? – Rehaan Mazid Dec 01 '22 at 15:17