cancel
Showing results for 
Search instead for 
Did you mean: 

SetControllerVibration - how to stop it?

xlar54
Level 2
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 5

xlar54
Level 2
Heres 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();
    }

FocusVRGames
Level 5
Don'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 0

OVRInput.SetControllerVibration(0, 0, OVRInput.Controller.RTouch);

To give me a little more control I wrote a coroutine to control the vibration length

IEnumerator 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);
}
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 gun
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.

Anonymous
Not applicable
Just 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?!!

FocusVRGames
Level 5
I 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

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_EDITOR
            OVRHapticsClip clip = new OVRHapticsClip(soundClip);
            OVRHaptics.LeftChannel.Clear();
            OVRHaptics.LeftChannel.Queue(clip);
        #endif
    }