cancel
Showing results for 
Search instead for 
Did you mean: 

OVRHaptics sample code?

Nullzero
Honored Guest
Howdy,

Was very happy to get my Touch controllers courtesy of Oculus, and they work great with the Oculus World Demo and Bullet Train, etc.

However, when using Unity 5.4.0.p3, I am having trouble getting them to vibrate. I assume I am using the API incorrectly? Here is the code I am trying to run, inside Update():

        if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger))
{
byte[] samples = { 255, 255, 255, 0, 128, 0, 255 };
OVRHapticsClip clip = new OVRHapticsClip(samples, 7);
OVRHaptics.Channels[0].Queue(clip);
OVRHaptics.Channels[1].Queue(clip);

Debug.Log("PrimaryIndexTrigger button pressed");
}

Any help? I even tried using the now somewhat deprecated "SetControllerVibration()", but the controllers still don't vibrate.

They vibrate fine inside the demos just fine.

OVRManager says:
Unity v5.4.0p3, Oculus Utilities v1.7.0, OVRPlugin v1.7.0, SDK v1.7.0

Also, debugging the OVRHaptic.Process() function, I noticed that inside this return value:
            var hapticsState = OVRPlugin.GetControllerHapticsState(m_controller);
hapticsState.SamplesAvailable and SamplesQueued is always 0. However, m_pendingClips.Count is climbing with every button press. I'm not sure if that is related or not, as I'm so new to the API.

Any help would be much appreciated!
8 REPLIES 8

ChrisCas
Member
Haptics is still working very strangely.

The best I have been able to come up with is this line of code which gets me a vibration every once and a while.

OVRInput.SetControllerVibration(150f, 0.1f, OVRInput.Controller.LTouch);

chooch709
Explorer
When testing haptics I've found these two requirements:
1.)  You'll want fresh batteries in your controllers, haptics look like they stop working once you start getting to low battery levels.
2.)  The HMD must be on your face, or the sensor blocked.  Haptics don't trigger if the headset is sitting on your desk.

#2 can make for some tricky debugging but it's been do-able.  The sample app haptics seem to work fine for me, and in RBVR we've been making good use of the waveform api's.

Nullzero
Honored Guest
2.)  The HMD must be on your face, or the sensor blocked.  Haptics don't trigger if the headset is sitting on your desk.

Wow, okay, that did it. XD

Hours of debugging, and all I needed to do was put the damn headset on.

Thanks. :s

mfmf
Oculus Staff
Yes, the headset having to be on got me once or twice as well.

I'll be posting a very simple OVRHaptics sample for Unity soon, with the new API. We're eager to get folks' feedback. It's still a little rough around the edges, though, and SetControllerVibration is still perfectly fine.

treefortress
Protege
Throw a piece of tape over the light sensor, save a little pain 🙂

VRoximity
Explorer
Did the OVRHaptics sample for Unity ever get posted?

ChrisCas
Member
I don't think so But I figured it all out in my HapticHelper script.

https://forums.oculus.com/vip/discussion/44028/haptic-helper-for-unity#latest

VRoximity
Explorer
Thank you for replying ChrisCas. I already downloaded your helper. I'll just go with that for now! 🙂