Forum Discussion
willtionvon
9 years agoHonored Guest
the "OVRHapticsClip" can't work, help me to write some codes for example.
if use the "OVRHapticsClip " create with " AudioClips" it cause unity crash, there is a Infinite loop in "while"
I find the crux of problem: "OVRHaptics.Config.SampleRateHz" is zero!! and can't get the right value from "OVRHaptics.Config",all value is zero in "OVRHaptics.Config".
I just want to make the touch vbration, somebady can help me? tell me how to use vbration API with some right code for example.
the "OVRInput.SetControllerVibration" is not my need, it can't control vibration duration.
please.
private void InitializeFromAudioFloatTrack(float[] sourceData, double sourceFrequency, int sourceChannelCount, int sourceChannel)
{
double stepSizePrecise = sourceFrequency / OVRHaptics.Config.SampleRateHz;
int stepSize = (int)stepSizePrecise;
double stepSizeError = stepSizePrecise - stepSize;
double accumulatedStepSizeError = 0.0f;
int length = sourceData.Length;
Count = 0;
Capacity = length / sourceChannelCount / stepSize + 1;
Samples = new byte[Capacity * OVRHaptics.Config.SampleSizeInBytes];
int i = sourceChannel % sourceChannelCount;
while (i < length)
{
if (OVRHaptics.Config.SampleSizeInBytes == 1)
{
WriteSample((byte)(Mathf.Clamp01(Mathf.Abs(sourceData)) * System.Byte.MaxValue)); // TODO support multi-byte samples
}
i+= stepSize * sourceChannelCount;
accumulatedStepSizeError += stepSizeError;
if ((int)accumulatedStepSizeError > 0)
{
i+= (int)accumulatedStepSizeError * sourceChannelCount;
accumulatedStepSizeError = accumulatedStepSizeError - (int)accumulatedStepSizeError;
}
}
}
I find the crux of problem: "OVRHaptics.Config.SampleRateHz" is zero!! and can't get the right value from "OVRHaptics.Config",all value is zero in "OVRHaptics.Config".
I just want to make the touch vbration, somebady can help me? tell me how to use vbration API with some right code for example.
the "OVRInput.SetControllerVibration" is not my need, it can't control vibration duration.
please.
3 Replies
Replies have been turned off for this discussion
- FocusVRGamesAdventurerFor what its worth I have the below and it works fine with lots of different sounds files might be worth a test?, I included a link to a sound file I've just used in a testusing System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Haptics : MonoBehaviour
{
OVRHapticsClip hapticsClip;
public AudioClip pickupClip;
public void activatePickUpHaptics()
{
hapticsClip = new OVRHapticsClip(pickupClip);
OVRHaptics.RightChannel.Mix(hapticsClip);
}
}
I attached that to an empty GameObject and add all my sounds files and attached that GameObject to a Haptics property on my GameController
I can then call haptics from anywhere in my game with gameController.Haptics.activatePickUpHaptics();
This is the sound I used in the test before posting so I know it should work
https://www.freesound.org/people/luckylittleraven/sounds/223078/
Only thing I noticed if you don't have the headset on and holding the controller the haptics wont play.
Hope that helps - AnonymousHey, I'm having the same crash in Unity from OVRHapticsClip(). No errors, just goes non responsive, mind if I ask what Unity version you are using?
- willtionvonHonored GuestI get! the problem is solved,thanks everybody. As shown below,if "version" go to the first branch(true), the value is right, or else the value is initial zero.I just update my Unity to 5.5 version, it can work.
public static HapticsDesc GetControllerHapticsDesc(uint controllerMask)
{
if (version >= OVRP_1_6_0.version)
{
return OVRP_1_6_0.ovrp_GetControllerHapticsDesc(controllerMask);
}
else
{
return new HapticsDesc();
}
}
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 4 years ago
- 9 months ago