unity-game-enginevirtual-realitysteamsteamvr

How to disable teleport Steam VR/Unity for one controller


The goal is to teleport with only one controller.

Should it be done via Action Sets or could it be done via Event Trigger? I could not find anything specific related to the controllers in the Hand script also.

Using the Action Sets should I use the per hand option and customize which settings? Then, how could I create I field in the Inspector?

Thank you very much!


Solution

  • Try getting a reference to your controllers SteamVR_Behaviour_Pose component and just check if it is the controller you want to do the teleporting with. SteamVR_Input_Sourcesis a enum that is used to identify your vive hardware.

    public SteamVR_Behaviour_Pose pose;
    
    if(pose.inputSource == SteamVR_Input_Sources.LeftHand)
    {
        //do stuff
    }
    

    Be careful tho. I don't quite remember but I think this can cause a NullReferenceExceptionif the hardware you are trying to access is not connected.

    You could also, as you already thought about, use the ActionSets and use different actions for both hands. That should also work, I just never tried it.

    As a bonus:

    public SteamVR_Action_Boolean action = SteamVR_Input.GetBooleanAction("YourActionName");
    
    if (action.GetStateUp(pose.inputSource))
    {
        //do even more stuff
    }
    

    Thats how you check for actions in your script. Took me a long time of reading docs to find out myself.

    Hope this helps!