Created
May 19, 2020 18:46
-
-
Save corycorvus/2b0788719f06fc162a8d5466ba58ac4d to your computer and use it in GitHub Desktop.
Haptic Vibrate Controller SteamVR and Oculus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.XR; | |
using Valve.VR; | |
// simple library and examples for XR haptics | |
// note: controllers must be tracking to use haptics | |
// other examples: https://vrtoolkit.readme.io/docs/vrtk_interacthaptics | |
public static class HapticPulse | |
{ | |
public static void PulseAll() { } | |
public static void PulseLeft() { } | |
public static void PulseRight() { } | |
// https://valvesoftware.github.io/steamvr_unity_plugin/tutorials/SteamVR-Input.html | |
static void HapticPulseSteam() | |
{ | |
Debug.Log("Haptic SteamVR"); | |
SteamVR_Actions.default_Haptic[SteamVR_Input_Sources.LeftHand].Execute(0, 1, 10, 1); | |
SteamVR_Actions.default_Haptic[SteamVR_Input_Sources.RightHand].Execute(0, 1, 10, 1); | |
//SteamVR_Actions.default_Haptic[SteamVR_Input_Sources.RightHand].Execute(0f, 0.5f, 160, 0.5f); | |
} | |
// https://docs.unity3d.com/2019.1/Documentation/ScriptReference/XR.InputDevice.SendHapticImpulse.html | |
// https://docs.unity3d.com/2018.3/Documentation/Manual/xr_input.html | |
// todo: ifdef for unity xr | |
static void HapticPulseUnity() | |
{ | |
Debug.Log("Haptic Unity"); | |
InputDevice device = InputDevices.GetDeviceAtXRNode(XRNode.RightHand); | |
HapticCapabilities capabilities; | |
if (device.TryGetHapticCapabilities(out capabilities)) | |
if (capabilities.supportsImpulse) | |
device.SendHapticImpulse(0, 0.5f, 1.0f); | |
device = InputDevices.GetDeviceAtXRNode(XRNode.LeftHand); | |
if (device.TryGetHapticCapabilities(out capabilities)) | |
if (capabilities.supportsImpulse) | |
device.SendHapticImpulse(0, 0.5f, 1.0f); | |
} | |
#if PLATFORM_OCULUS | |
// https://developer.oculus.com/documentation/unity/unity-haptics/ | |
static void HapticPulseOculus() | |
{ | |
Debug.Log("Haptic Oculus"); | |
OVRInput.SetControllerVibration(1, 1, OVRInput.Controller.RTouch); | |
OVRInput.SetControllerVibration(1, 1, OVRInput.Controller.LTouch); | |
} | |
#endif | |
} |
This works like a charm, thank you so much for sharing ✨
gracias a mi tambien me funciono una parte, gracias.
for input_actions in not avalible
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey thanks so much for sharing, I used part of your Unity function and it worked perfectly!