How to get the motion controllers to work in Unity?

I’m trying to get a Samsung Mixed Reality HMD working in Unity with the motion controllers.

I’ve downloaded the MRTP4 build, installed the Dev.2017.2.1 unity packages into my project, and ran one of the examples scenes after the Cliff House portal is running. When I Play the scene, it doesn’t send any data to the HMD. When I try to enable “Target Occluded Devices” under the “Mixed Reality Toolkit > Apply Mixed Reality Project Settings” I get an error: “Switching to Universal Windows Platform:MetroSupport is disabled”. Thoughts?

I’m able to have the HMD working in 2017.2.0f3, but I can’t get the motion controllers to show.

Any help would be appreciated. Thanks.

I’m not sure about any specifics to the Mixed Reality Toolkit (no Unity dev wrote that, you’d have better luck asking into that here: GitHub - microsoft/MixedRealityToolkit-Unity: This repository is for the legacy Mixed Reality Toolkit (MRTK) v2. For the latest version of the MRTK please visit https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity), but controllers don’t appear in Unity by default (they might with the toolkit, I have no idea - again, you’d have better luck asking around on that github site I linked). You have to render in proxy objects at the position and rotation reported from either InteractionManager or InputTracking.GetLocalPosition/GetLocalRotation.

1 Like
  1. Download this asset into your project -
    GitHub - microsoft/MixedRealityToolkit-Unity: This repository is for the legacy Mixed Reality Toolkit (MRTK) v2. For the latest version of the MRTK please visit https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity

  2. Check out the ‘Assets/HoloToolkit-Examples/MotionControllers-GrabMechanics/’ scene.

  3. In that project they have replaced the controllers with cubes. In order to get the controllers, delete the prefab from Left Controller Override and Right Controller Override.

  4. Those public variables are optional. If blank, the default motion controllers are shown.

Do you know why you cant pick up things with the controllers unless you use the alternate controller which is a box?

What I did was download steamVR in unity, then went to steamvr-interaction system-samples then ran the scene in that folder.
I can without any problems use the mixed reality controllers in the scene to teleport, grab/throw objects, use remote, use bow and arrow.
My only gripe is that I can’t find out how to get joystick movement, something so simple, yet nothing online.

edit after a few months :smile: :
I have forgotten what I did, there was a tutorial around the internet on how to map steamVR inputs and use them IN unity, in the steam VR mapping section when you map buttons, you have to create a string “action” that is recognized here in unity, mine were joyPosV and grabAction

public class PlayerMovement : MonoBehaviour
{
    public SteamVR_Action_Boolean grabAction = SteamVR_Actions.default_GrabGrip;
    public GameObject VRcamera;
   // public GameObject cameraDir;
    public GameObject player;
    private bool _mInverted = false;
    private const float VERTICAL_LIMIT = 60f;
    private float _mHorizontalTurnSpeed = 80f;
    private float _mVerticalTurnSpeed = 2.5f;
    public float rotationSensitivity = 2F;
    public float movementSensitivity = 3f;
    public float sprintSensitivity = 2f;
    private Vector3 playerPos;


    public Vector2 getTrackPadPosLeft()
    {
        Vector2 joyPosV = SteamVR_Actions.default_joyPos.GetAxis(SteamVR_Input_Sources.LeftHand);
        return joyPosV;
    }

    public Vector2 getTrackPadPosRight()
    {
        Vector2 joyPosV = SteamVR_Actions.default_joyPos.GetAxis(SteamVR_Input_Sources.RightHand);
        return joyPosV;
    }


    float GetAngle(float input)
    {
        if (input < 0f)
        {
            _mInverted = true;
            return -Mathf.LerpAngle(0, VERTICAL_LIMIT, -input);
        }
        else if (input > 0f)
        {
            _mInverted = false;
            return Mathf.LerpAngle(0, VERTICAL_LIMIT, input);
        }
        return 0f;
    }

    // Update is called once per frame
    void Update()
    {
    

        if (getTrackPadPosLeft().x > 0.2f || getTrackPadPosLeft().x < -0.2f || getTrackPadPosLeft().y > 0.2f || getTrackPadPosLeft().y < -0.2f)
        {
            // Handle movement via joystick
            Quaternion orientation = Camera.main.transform.rotation;
//we initiate both joysticks in the same time so they work in the same time not one by one
            Vector3 moveDirection = orientation * Vector3.forward * getTrackPadPosLeft().y + orientation * Vector3.right * getTrackPadPosLeft().x;
            Vector3 pos = player.transform.position;
            //Sprint
            if (grabAction.GetState(SteamVR_Input_Sources.LeftHand) == true)
            {
                pos.x += moveDirection.x * (movementSensitivity * sprintSensitivity) * Time.deltaTime;
                pos.z += moveDirection.z * (movementSensitivity * sprintSensitivity) * Time.deltaTime;
            }
            else
            {
                pos.x += moveDirection.x * movementSensitivity * Time.deltaTime;
                pos.z += moveDirection.z * movementSensitivity * Time.deltaTime;
            }
            player.transform.position = pos;

        }
       
        if (getTrackPadPosRight().x > 0.2f || getTrackPadPosRight().x < -0.2f || getTrackPadPosRight().y > 0.2f || getTrackPadPosRight().y < -0.2f)
        {
            Vector3 euler = player.transform.rotation.eulerAngles;
            float angle;
            if (_mInverted)
            {
                angle = GetAngle(getTrackPadPosRight().y);
            }
            else
            {
                angle = GetAngle(-getTrackPadPosRight().y);
            }
            euler.x = Mathf.LerpAngle(euler.x, angle, _mVerticalTurnSpeed * Time.deltaTime);
            euler.y += getTrackPadPosRight().x * _mHorizontalTurnSpeed * Time.deltaTime;
            player.transform.rotation = Quaternion.Euler(euler);

            VRcamera.transform.eulerAngles = new Vector3(0, VRcamera.transform.eulerAngles.y + getTrackPadPosRight().x * rotationSensitivity, 0);

        }

    
     
     

    }

 
  }
1 Like