Vibration/Haptic feedback for Oculus Rift
nezix opened this issue · 7 comments
Haptic feedback does not work for Oculus rift controllers when not using SteamVR, calling TriggerHapticPulse does not make the controllers vibrate.
- Steps to reproduce:
- Create a new project in Unity 2019.4.21
- Import VIU via Asset Store
- Install Oculus XR plugin package & activate it in VIU Settings
- Load VIU Teleport scene
- Add the following TestHaptic.cs script to a gameobject
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HTC.UnityPlugin.Vive;
using HTC.UnityPlugin.Utility;
public class TestHaptic : MonoBehaviour{
int idf = 0;
//Vibrate both controllers every 100 frames
void Update() {
idf++;
if (idf % 100 == 0) {
idf = 0;
goHaptic();
}
}
public void goHaptic() {
Debug.Log("Wizzzz");
ViveInput.TriggerHapticPulse(HandRole.LeftHand, 500);
ViveInput.TriggerHapticPulse(HandRole.RightHand, 500);
}
}
This works using SteamVR but not using the Oculus runtime.
I also have this warning spammed:
Device Oculus Touch Controller - Left doesn't have float feature ThumbTouch. Return default value instead.
UnityEngine.Debug:LogWarningFormat (string,object[])
HTC.UnityPlugin.VRModuleManagement.UnityXRModule:GetDeviceFeatureValueOrDefault (UnityEngine.XR.InputDevice,UnityEngine.XR.InputFeatureUsage`1<single>) (at Assets/HTC.UnityPlugin/VRModule/Modules/UnityXRModule.cs:893)
HTC.UnityPlugin.VRModuleManagement.UnityXRModule:UpdateOculusControllerState (HTC.UnityPlugin.VRModuleManagement.IVRModuleDeviceStateRW,UnityEngine.XR.InputDevice) (at Assets/HTC.UnityPlugin/VRModule/Modules/UnityXRModule.cs:673)
HTC.UnityPlugin.VRModuleManagement.UnityXRModule:UpdateControllerState (HTC.UnityPlugin.VRModuleManagement.IVRModuleDeviceStateRW,UnityEngine.XR.InputDevice) (at Assets/HTC.UnityPlugin/VRModule/Modules/UnityXRModule.cs:412)
HTC.UnityPlugin.VRModuleManagement.UnityXRModule:BeforeRenderUpdate () (at Assets/HTC.UnityPlugin/VRModule/Modules/UnityXRModule.cs:275)
HTC.UnityPlugin.VRModuleManagement.VRModule:BeforeRenderUpdateModule () (at Assets/HTC.UnityPlugin/VRModule/VRModuleManager.cs:326)
UnityEngine.GUIUtility:ProcessEvent (int,intptr)
@nezix Simply update your haptic API to TriggerHapticVibration.
The warning spam message is because ThumbTouch and IndexTouch features not supported.
If you don't want to see the warning messages, please modify the script as follows,
In Assets\HTC.UnityPlugin\VRModule\Modules\UnityXRModule.cs,
line 671,
bool thumbrest = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage<bool>("Thumbrest"));
//float indexTouch = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage<float>("IndexTouch"));
//float thumbTouch = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage<float>("ThumbTouch")); // Not in use
state.SetButtonTouch(VRModuleRawButton.Touchpad, thumbrest);
//state.SetButtonTouch(VRModuleRawButton.Trigger, indexTouch >= 1.0f);
if ((device.characteristics & InputDeviceCharacteristics.Left) != 0)
{
bool menuButton = GetDeviceFeatureValueOrDefault(device, CommonUsages.menuButton);
state.SetButtonPress(VRModuleRawButton.System, menuButton);
}
I will fix the TriggerHapticPulse API later, thanks!
Thanks for your answer,
I tried to replace ViveInput.TriggerHapticPulse(HandRole.LeftHand, 500);
by ViveInput.TriggerHapticVibration(HandRole.LeftHand);
but no luck on my part.
If I directly call OVRInput.SetControllerVibration(0.9f, 0.5f, OVRInput.Controller.RTouch);
the right controller vibrates.
@nezix I use ViveInput.TriggerHapticVibration(HandRole.LeftHand, 500);
Could you try this?
I tried this too, same result.
Is there something I am missing ?
Where did you attach your script to?
The vibration is kinda weak for the value 500.
I deleted and recreated an empty project and follow the first post recipe and it works now with TriggerHapticVibration
...
Weird !
Sorry for the waste of time.