Search Unity

Question Make Vive controller vibrate when object is destroyed. SteamVR

Discussion in 'VR' started by InMindStudios, Jan 26, 2021.

  1. InMindStudios

    InMindStudios

    Joined:
    Dec 5, 2020
    Posts:
    10
    Hey guys;
    The web is filled with outdated and no longer working guides and it makes me loose hours every day in wasted time an I cant find ANY guide for this that makes sense.

    I am building a Sword VR game in Unity and SteamVR. I have been trying for two days to get haptic feedback when my sword destroys an enemy.

    I aim to put the trigger for the haptic on my enemy script:


    Code (CSharp):
    1.  
    2. GameObject[] newGOs = new GameObject[2];
    3.             if (OptionalTargetObject == null)
    4.             {
    5.                 newGOs[0] = Instantiate(gameObject) as GameObject;
    6.                 newGOs[0].name = gameObject.name;
    7.                 newGOs[1] = gameObject;
    8.                 NextTarget.SetActive(true);
    9. //This is where I want the haptic command to go to give the controller a buzz.
    10.             }
    Thank you in advance! :)
     
  2. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,822
    SteamVR is now directly supported by Valve, we suggest checking out their latest SteamVR plugin. Please post any questions you have on their Github so their team can address.
     
  3. CorvusVR

    CorvusVR

    Joined:
    Sep 15, 2014
    Posts:
    5
    SteamVR

    Code (CSharp):
    1.     // https://valvesoftware.github.io/steamvr_unity_plugin/tutorials/SteamVR-Input.html
    2.     static void HapticPulseSteam()
    3.     {
    4.         Debug.Log("Haptic SteamVR");
    5.         SteamVR_Actions.default_Haptic[SteamVR_Input_Sources.LeftHand].Execute(0, 1, 10, 1);
    6.         SteamVR_Actions.default_Haptic[SteamVR_Input_Sources.RightHand].Execute(0, 1, 10, 1);
    7.         //SteamVR_Actions.default_Haptic[SteamVR_Input_Sources.RightHand].Execute(0f, 0.5f, 160, 0.5f);
    8.     }
    9.  
    Unity

    Code (CSharp):
    1. // https://docs.unity3d.com/2019.1/Documentation/ScriptReference/XR.InputDevice.SendHapticImpulse.html
    2.     // https://docs.unity3d.com/2018.3/Documentation/Manual/xr_input.html
    3.     // todo: ifdef for unity xr
    4.     static void HapticPulseUnity()
    5.     {
    6.         Debug.Log("Haptic Unity");
    7.         InputDevice device = InputDevices.GetDeviceAtXRNode(XRNode.RightHand);
    8.         HapticCapabilities capabilities;
    9.         if (device.TryGetHapticCapabilities(out capabilities))
    10.             if (capabilities.supportsImpulse)
    11.                 device.SendHapticImpulse(0, 0.5f, 1.0f);
    12.         device = InputDevices.GetDeviceAtXRNode(XRNode.LeftHand);
    13.         if (device.TryGetHapticCapabilities(out capabilities))
    14.             if (capabilities.supportsImpulse)
    15.                 device.SendHapticImpulse(0, 0.5f, 1.0f);
    16.     }