Welcome to the Oculus Developer Forums!

Your participation on the forum is subject to the Oculus Code of Conduct.

In general, please be respectful and kind. If you violate the Oculus Code of Conduct, your access to the developer forums may be revoked at the discretion of Oculus staff.

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.
Tagged:

Comments

  • xlar54xlar54 Posts: 12
    NerveGear
    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();
        }
  • FocusVRGamesFocusVRGames Posts: 93 Oculus Start Member
    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.
  • AlexLeggAlexLegg Posts: 5
    NerveGear
    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?!!
  • FocusVRGamesFocusVRGames Posts: 93 Oculus Start Member
    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
Sign In or Register to comment.