Search Unity

Question Haptics on correct controller when using a drill

Discussion in 'XR Interaction Toolkit and Input' started by markasuter, Mar 17, 2021.

  1. markasuter

    markasuter

    Joined:
    May 20, 2019
    Posts:
    24
    Using the XRIT I can pick up the drill, and upon being Activated (pulling the trigger) the correct controller will vibrate...but only if the other hand is nowhere near it (not within the collider). If both hands are near the drill, both hands vibrate. I know why this is, but it's the only solution I've come up with, as you can see in the script below.

    I THINK what I need to do is add an "if being held by Left Controller", but I don't know how to write that, just how to write if the tagged object entered or exited the drill collider.

    Each of the LeftHand and RightHand are tagged CtrlL and CtrlR respectively, to accommodate my script on the drill:
    Code (CSharp):
    1.     public XRBaseController xrbR;
    2.     public XRBaseController xrbL;
    3.     private bool readyLeft = false;
    4.     private bool readyRight = false;
    5.  
    6. private void OnTriggerEnter(Collider other)
    7.     {
    8.         if (other.gameObject.CompareTag("CtrlR")){
    9.             Debug.Log("Enter RIGHT");
    10.             readyRight = true;
    11.             //readyLeft = false;
    12.         }
    13.  
    14.         if (other.gameObject.CompareTag("CtrlL"))
    15.         {
    16.             Debug.Log("Enter LEFT");
    17.             readyLeft = true;
    18.             //readyRight = false;
    19.         }
    20.     }
    21.  
    22.     private void OnTriggerExit(Collider other)
    23.     {
    24.         if (other.gameObject.CompareTag("CtrlR"))
    25.         {
    26.             Debug.Log("Exit RIGHT");
    27.             readyRight = false;
    28.            
    29.         }
    30.  
    31.         if (other.gameObject.CompareTag("CtrlL"))
    32.         {
    33.             Debug.Log("Exit LEFT");
    34.             readyLeft = false;
    35.         }
    36.     }
    37.  
    38.  
    39.     public void brrrpR()
    40.     {
    41.         if(readyRight == true)
    42.         {
    43.             xrbR.SendHapticImpulse(1.0f, 1.0f);
    44.             Debug.Log("Brrrrrrrrrp RIIIIGHT");
    45.         }
    46.     }
    47.  
    48.     public void brrrpL()
    49.     {
    50.         if(readyLeft == true)
    51.         {
    52.             xrbL.SendHapticImpulse(1.0f, 1.0f);
    53.             Debug.Log("Brrrrrrrrrp LEFFFFT");
    54.         }    
    55.     }
    drill-activate.PNG drill-vr.PNG