Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

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.

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, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.

Supporting both Single and Multiple Motion Controller Inputs in Unity?

EvoxVREvoxVR
edited February 2018 in Q&A and Discussions

Hi Everyone I am developing an Immersive app and having a little trouble figuring out how to support both single an dual Motion Controller inputs( if that is even possible) . I will include my code below but currently I am polling the Interaction source state of both controllers and and applying my interaction logic after they meet the input thresholds.

What I'm trying to do is get the number of current Interaction source states using var interactionSourceState = InteractionManager.GetCurrentReading (); and based on the length of the returned array . Determine if one or two controllers are being detected and then handle the input based on the respective indexes for one of both controllers. Is my thinking incorrect? Am I missing something about how the Interaction Source States are working ?

Here is my code for reference of how I am implementing this :

var interactionSourceState = InteractionManager.GetCurrentReading ();

      //*** If Single controller 
      if (interactionSourceState.Length == 1) {
      //*** Controller Stick 1
          if (interactionSourceState [0].thumbstickPosition.x >= 0.1f) {
              Debug.Log (" Left Stick moved Left");
              
          }

          if (interactionSourceState [0].thumbstickPosition.x <= -0.1f) {
              Debug.Log (" Left Stick moved Right");
              
          }

          //*** Touchpad 1
          if (interactionSourceState [0].touchpadPosition.x >= 0.1f) {
              Debug.Log (" Left Stick moved Left");
          
          }


          if (interactionSourceState [0].touchpadPosition.x <= -0.1f) {
              Debug.Log (" Left Stick moved Right");
              Vector3 rotation = Vector3.up * 3.0f * Time.deltaTime * sensitivity;
              this.transform.Rotate (rotation);
          }

          //*** If two controllers
      } else if (interactionSourceState.Length > 1) {
          //*** Controller Stick 1
          if (interactionSourceState [0].thumbstickPosition.x >= 0.1f) {
              Debug.Log (" Left Stick moved Left");
          
          }

          if (interactionSourceState [0].thumbstickPosition.x <= -0.1f) {
              Debug.Log (" Left Stick moved Right");
          
          }

          //*** Touchpad 1
          if (interactionSourceState [0].touchpadPosition.x >= 0.1f) {
              Debug.Log (" Left Stick moved Left");
          
          }


          if (interactionSourceState [0].touchpadPosition.x <= -0.1f) {
              Debug.Log (" Left Stick moved Right");
          
          }

          //*** Control Stick 2
          if (interactionSourceState [1].thumbstickPosition.x >= 0.1f) {
              Debug.Log (" Right Stick moved Left");
      
          }

          if (interactionSourceState [1].thumbstickPosition.x <= -0.1f) {
              Debug.Log (" Right Stick moved Right");
      
          }

          //*** Touchpad 2
          if (interactionSourceState [1].touchpadPosition.x >= 0.1f) {
              Debug.Log (" Left Stick moved Left");
          
          }


          if (interactionSourceState [1].touchpadPosition.x <= -0.1f) {
              Debug.Log (" Left Stick moved Right");
          
          }

      }

Thank you very much , any and all input is appreciated I feel like I might be missing something in my implementation .

Tagged:

Best Answer

  • EvoxVREvoxVR
    Answer ✓

    Thanks a ton for the resource I was getting issues when importing the package into unity 2017.3.0f3 however I was able to finally see the issues in my code one of my references was stating to check an input source.length if it was greater than 0 instead of checking if the input source.length == 1; . Changing it to check if we have a specific case of a single input source seemed to work for both controllers when only one was enabled.

Answers

  • Why not use the mixed reality toolkit? It handles both single and dual motion controllers. Or at least reference their setup.

    Taqtile

  • @mark_grossnickle said:
    Why not use the mixed reality toolkit? It handles both single and dual motion controllers. Or at least reference their setup.

    I have never heard of the Mixed Reality toolkit, I will take a look at it though , thanks for the lead @mark_grossnickle .

  • mark_grossnickle gave the right link.
    I also want to add a few points.
    You can also refer to this scene.

    And maybe the introduction of Input can help you to realize it.

  • demonixisdemonixis
    edited February 2018

    Hello,

    Why don't you use the Unity's built-in implementation?

    var leftPosition = InputTracking.GetLocalPosition(XRNode.LeftHand);
    var leftOrientation = InputTracking.GetLocalRotation(XRNode.LeftHand);

    Also you can use the input system to get button/axis states. Or use my input manager which work for Oculus/Vive/Windows MR. It works like that

    var trigger = XRInput.Instance.GetButtonDown(XRButton.Trigger, isLeftHand);
    var touchpad = XRInput.Instance.GetAxis2D(XRAxis.SecondaryTouchPad, isLeftHand);

    Hope it can help.

    French XR/MR developer / Indie Game Developer

  • EvoxVREvoxVR
    Answer ✓

    Thanks a ton for the resource I was getting issues when importing the package into unity 2017.3.0f3 however I was able to finally see the issues in my code one of my references was stating to check an input source.length if it was greater than 0 instead of checking if the input source.length == 1; . Changing it to check if we have a specific case of a single input source seemed to work for both controllers when only one was enabled.

Sign In or Register to comment.