Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to get the motion controllers to work in Unity?

Discussion in 'VR' started by DigitalAdam, Nov 10, 2017.

  1. DigitalAdam

    DigitalAdam

    Joined:
    Jul 18, 2007
    Posts:
    1,192
    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.
     
  2. unity_andrewc

    unity_andrewc

    Unity Technologies

    Joined:
    Dec 14, 2015
    Posts:
    201
    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: https://github.com/Microsoft/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.
     
    ROBYER1 likes this.
  3. jamienorthampton

    jamienorthampton

    Joined:
    Jul 24, 2017
    Posts:
    1
    1. Download this asset into your project -
    https://github.com/Microsoft/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.
     
  4. foxvalleysoccer

    foxvalleysoccer

    Joined:
    May 11, 2015
    Posts:
    108
    Do you know why you cant pick up things with the controllers unless you use the alternate controller which is a box?
     
  5. Tsilliev

    Tsilliev

    Joined:
    Jan 21, 2014
    Posts:
    34
    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 :D :
    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
    Code (CSharp):
    1. public class PlayerMovement : MonoBehaviour
    2. {
    3.     public SteamVR_Action_Boolean grabAction = SteamVR_Actions.default_GrabGrip;
    4.     public GameObject VRcamera;
    5.    // public GameObject cameraDir;
    6.     public GameObject player;
    7.     private bool _mInverted = false;
    8.     private const float VERTICAL_LIMIT = 60f;
    9.     private float _mHorizontalTurnSpeed = 80f;
    10.     private float _mVerticalTurnSpeed = 2.5f;
    11.     public float rotationSensitivity = 2F;
    12.     public float movementSensitivity = 3f;
    13.     public float sprintSensitivity = 2f;
    14.     private Vector3 playerPos;
    15.  
    16.  
    17.     public Vector2 getTrackPadPosLeft()
    18.     {
    19.         Vector2 joyPosV = SteamVR_Actions.default_joyPos.GetAxis(SteamVR_Input_Sources.LeftHand);
    20.         return joyPosV;
    21.     }
    22.  
    23.     public Vector2 getTrackPadPosRight()
    24.     {
    25.         Vector2 joyPosV = SteamVR_Actions.default_joyPos.GetAxis(SteamVR_Input_Sources.RightHand);
    26.         return joyPosV;
    27.     }
    28.  
    29.  
    30.     float GetAngle(float input)
    31.     {
    32.         if (input < 0f)
    33.         {
    34.             _mInverted = true;
    35.             return -Mathf.LerpAngle(0, VERTICAL_LIMIT, -input);
    36.         }
    37.         else if (input > 0f)
    38.         {
    39.             _mInverted = false;
    40.             return Mathf.LerpAngle(0, VERTICAL_LIMIT, input);
    41.         }
    42.         return 0f;
    43.     }
    44.  
    45.     // Update is called once per frame
    46.     void Update()
    47.     {
    48.    
    49.  
    50.         if (getTrackPadPosLeft().x > 0.2f || getTrackPadPosLeft().x < -0.2f || getTrackPadPosLeft().y > 0.2f || getTrackPadPosLeft().y < -0.2f)
    51.         {
    52.             // Handle movement via joystick
    53.             Quaternion orientation = Camera.main.transform.rotation;
    54. //we initiate both joysticks in the same time so they work in the same time not one by one
    55.             Vector3 moveDirection = orientation * Vector3.forward * getTrackPadPosLeft().y + orientation * Vector3.right * getTrackPadPosLeft().x;
    56.             Vector3 pos = player.transform.position;
    57.             //Sprint
    58.             if (grabAction.GetState(SteamVR_Input_Sources.LeftHand) == true)
    59.             {
    60.                 pos.x += moveDirection.x * (movementSensitivity * sprintSensitivity) * Time.deltaTime;
    61.                 pos.z += moveDirection.z * (movementSensitivity * sprintSensitivity) * Time.deltaTime;
    62.             }
    63.             else
    64.             {
    65.                 pos.x += moveDirection.x * movementSensitivity * Time.deltaTime;
    66.                 pos.z += moveDirection.z * movementSensitivity * Time.deltaTime;
    67.             }
    68.             player.transform.position = pos;
    69.  
    70.         }
    71.        
    72.         if (getTrackPadPosRight().x > 0.2f || getTrackPadPosRight().x < -0.2f || getTrackPadPosRight().y > 0.2f || getTrackPadPosRight().y < -0.2f)
    73.         {
    74.             Vector3 euler = player.transform.rotation.eulerAngles;
    75.             float angle;
    76.             if (_mInverted)
    77.             {
    78.                 angle = GetAngle(getTrackPadPosRight().y);
    79.             }
    80.             else
    81.             {
    82.                 angle = GetAngle(-getTrackPadPosRight().y);
    83.             }
    84.             euler.x = Mathf.LerpAngle(euler.x, angle, _mVerticalTurnSpeed * Time.deltaTime);
    85.             euler.y += getTrackPadPosRight().x * _mHorizontalTurnSpeed * Time.deltaTime;
    86.             player.transform.rotation = Quaternion.Euler(euler);
    87.  
    88.             VRcamera.transform.eulerAngles = new Vector3(0, VRcamera.transform.eulerAngles.y + getTrackPadPosRight().x * rotationSensitivity, 0);
    89.  
    90.         }
    91.  
    92.    
    93.      
    94.      
    95.  
    96.     }
    97.  
    98.  
    99.   }
     
    Last edited: May 2, 2019
    ROBYER1 likes this.