Forum Discussion
xlar54
9 years agoHonored Guest
SetControllerVibration - how to stop it?
So I have haptics working, but I need a way to stop it. It seems to run for about a second or two then quits. But essentially i only want it to vibrate when I touch something. No longer touching, I want to be able to stop it.
5 Replies
- xlar54Honored GuestHeres my code:void OnTriggerEnter(Collider col){if (col.name == "stickRight"){OVRInput.SetControllerVibration(.3f, 0.3f, OVRInput.Controller.RTouch);}if (col.name == "stickLeft"){OVRInput.SetControllerVibration(.3f, 0.3f, OVRInput.Controller.LTouch);}GetComponent<AudioSource>().Play();}
- FocusVRGamesAdventurerDon't mean to bring up an old thread but I found this thread while searching for an answer to stopping haptics and I found the solution so posting here for anyone else finding this post
To stop the haptics you just set the frequency and amplitude to to 0OVRInput.SetControllerVibration(0, 0, OVRInput.Controller.RTouch);
To give me a little more control I wrote a coroutine to control the vibration length
I put that into a new script called HapticsController and then created functions to suit, I.E this is my functions for when I shoot a gunIEnumerator Haptics(float frequency, float amplitude, float duration, bool rightHand, bool leftHand)
{
if(rightHand) OVRInput.SetControllerVibration(frequency, amplitude, OVRInput.Controller.RTouch);
if(leftHand) OVRInput.SetControllerVibration(frequency, amplitude, OVRInput.Controller.LTouch);
yield return new WaitForSeconds(duration);
if (rightHand) OVRInput.SetControllerVibration(0, 0, OVRInput.Controller.RTouch);
if (leftHand) OVRInput.SetControllerVibration(0, 0, OVRInput.Controller.LTouch);
}public void PlayShoot(bool rightHanded)
{
if(rightHanded) StartCoroutine(Haptics(1, 1, 0.3f, true, false));
else StartCoroutine(Haptics(1, 1, 0.3f, false, true));
}
Its worth noting that the vibrations will automatically stop after 3 seconds, so if you want to extend beyond 3 seconds you'd have to write something to handle that. - AnonymousJust what I was looking for, thank you!
I have had no luck getting audio clips to work as vibration, I don't suppose you have figured that out too?!!- badnproExplorer
This worked for me
public AudioClip testSound; // audo clip set// call method with sound clip vibrateOnSound(audioclip);void vibrateOnSound(AudioClip soundClip){#if UNITY_ANDROID && !UNITY_EDITOROVRHapticsClip clip = new OVRHapticsClip(soundClip);OVRHaptics.LeftChannel.Clear();OVRHaptics.LeftChannel.Queue(clip);#endif}
- FocusVRGamesAdventurerI used audio clips for haptics in Salvo, my first game however that was part of OVRHaptics which according to the documentation is now depreciated, so don't know how long support for it will be maintained.
Not sure why they depreciated that method because in my opinion control over haptics via audio files is a much more dynamic way of controlling them
I quickly wrote the below to test haptics with audio files in the latest Oculus Utilities and it still works if you want to use that method.public class TestHaptics : MonoBehaviour
{
private OVRHapticsClip hapticsClip;
public AudioClip testClip;
void Start()
{
hapticsClip = new OVRHapticsClip(testClip);
}
private void OnTriggerEnter(Collider other)
{
OVRHaptics.RightChannel.Mix(hapticsClip);
OVRHaptics.LeftChannel.Mix(hapticsClip);
}
}
Hope that helps.
Mike
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
- 3 years ago
- 3 years ago
- 4 months agoAnonymous