Search Unity

Question How to determine if left or right controller now that ControllerNode is removed

Discussion in 'XR Interaction Toolkit and Input' started by yulaw2k, Jan 13, 2021.

  1. yulaw2k

    yulaw2k

    Joined:
    Apr 25, 2014
    Posts:
    31
    In the previous release I would do something like when an interactable was grabbed from the OnSelect

    Code (CSharp):
    1. var xrNode = interactor.GetComponent<XrController>().controllerNode;
    2. leftOrRight= InputDevices.GetDeviceAtXRNode(xrNode);
    Now I know if its the left hand or the right hand that grabbed on object, but that controllerNode has been removed from the controller. Whats the proper way to determine this now?
     
    Last edited: Jan 14, 2021
  2. yulaw2k

    yulaw2k

    Joined:
    Apr 25, 2014
    Posts:
    31
    Some extra context.

    Old Controller
    upload_2021-1-14_13-11-25.png

    New Controller
    upload_2021-1-14_13-11-45.png
     
  3. Bender_R

    Bender_R

    Joined:
    May 21, 2018
    Posts:
    115
    Hi there, did you find a solution? I'm struggling with same issue.

    Thanks
     
  4. henymeny

    henymeny

    Joined:
    Apr 19, 2014
    Posts:
    10
    I use the input events system. then I have duplicate mappings for left and for right controllers. see XR Toolkit demo for example.

    Then I can take InputActionReference as parameter for my script, and use either action.performed event or action.ReadValue<T>()

    This method you can also have both controllers activate the same function but also know which one is the input source.
     
    Bender_R likes this.
  5. Bender_R

    Bender_R

    Joined:
    May 21, 2018
    Posts:
    115
    Thanks a lot! I'll try this
     
  6. henymeny

    henymeny

    Joined:
    Apr 19, 2014
    Posts:
    10
    I have learned that if it's a button action (like Activate or Select which are trigger and grip buttons respectively) action.triggered only gets updated on button push, not release or hold down. you can detect push with action.triggered, detect is down with action.phase == InputActionPhase.Start and up with action.phase != Start (specifically Waiting but note it can also be disabled or something)
     
  7. Bender_R

    Bender_R

    Joined:
    May 21, 2018
    Posts:
    115
    Ok. I've taken another approach, which feels very very dirty, but does the job. I give left and right hand a tag. This code is triggered on the OnSelectEntered event.

    Code (CSharp):
    1.         var controller = GetComponent<XRGrabInteractable>();
    2.  
    3.         if (controller.selectingInteractor.tag.Equals("HandLeft"))
    4.         {
    5.             isLeftHandHoldingGun = true;
    6.          }
    7.         else if (controller.selectingInteractor.tag.Equals("HandRight"))
    8.         {
    9.             isRightHandHoldingGun = true;
    10.         }