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:
GameObject[] newGOs = new GameObject[2];
if (OptionalTargetObject == null)
{
newGOs[0] = Instantiate(gameObject) as GameObject;
newGOs[0].name = gameObject.name;
newGOs[1] = gameObject;
NextTarget.SetActive(true);
//This is where I want the haptic command to go to give the controller a buzz.
}
Thank you in advance!
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.
SteamVR
// 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);
}
Unity
// 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);
}