Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
the5souls's avatar
the5souls
Protege
9 years ago
Solved

UPDATE: Getting the Touch haptics to activate? SOLVED

Hi, all. I've been scouring the web all day for Touch haptic examples in Unity, but it's been difficult finding any beginner-level example scripts.

Here's what I have roughly in "MyGunScript" that is attached to my "Rifle" game object:


public class MyGunScript{

OVRHapticsClip myHapticsClip;
public AudioClip myAudioClip;

void Start(){
myHapticsClip = new OVRHapticsClip (myAudioClip);
}

void Update(){
if (OVRInput.Get (OVRInput.Button.One)){
OVRHaptics.RightChannel.Mix (myHapticsClip);
}
}

}

And then I dragged a very loud gun shot sound into the public "myAudioClip" in the script. However, I feel no vibration in either left or right Touch controllers when I pull the trigger during testing.

Any clue as to what I'm doing wrong here?

Thanks!
  • So... Today, I learned that the Touch haptics only work if you have the headset actually on your head. I've been Unity testing by holding up my headset with one hand, holding a Touch controller with my other hand, and looking through the Unity play preview window this whole time.

    When I put on the headset, the little sensor inside detects that I'm wearing it, and it finally enables the controller haptics. When it doesn't detect that I'm wearing it, it disables it.

    The script above works fine. I hope this help other beginners like me!

    I'm such a dummy.  :s

5 Replies

  • So... Today, I learned that the Touch haptics only work if you have the headset actually on your head. I've been Unity testing by holding up my headset with one hand, holding a Touch controller with my other hand, and looking through the Unity play preview window this whole time.

    When I put on the headset, the little sensor inside detects that I'm wearing it, and it finally enables the controller haptics. When it doesn't detect that I'm wearing it, it disables it.

    The script above works fine. I hope this help other beginners like me!

    I'm such a dummy.  :s
  • The initialization you did inside the Start function make crash my unity and i can't understand why.

    I was using a code kinda similar to this but i'm not able to get the haptics work because i can't initialize that.. since it's crashing all the time
  • Hmm... and you also dragged an audio clip into the "myAudioClip" section in your object Unity?

  • Welby said:

    The initialization you did inside the Start function make crash my unity and i can't understand why.

    I was using a code kinda similar to this but i'm not able to get the haptics work because i can't initialize that.. since it's crashing all the time


    have you solved the problem? how to do?



  • Welby said:

    The initialization you did inside the Start function make crash my unity and i can't understand why.

    I was using a code kinda similar to this but i'm not able to get the haptics work because i can't initialize that.. since it's crashing all the time


    have you solved the problem? how to do?

    Don't forget you need to inherit from Monobehaviour. This would be the full script:

    using System.Collections;
    using UnityEngine;

    public class MyGunScript : MonoBehaviour
    {
      OVRHapticsClip myHapticsClip;
    public AudioClip myAudioClip;

    void Start(){
    myHapticsClip = new OVRHapticsClip (myAudioClip);
    }

    void Update(){
    if (OVRInput.Get (OVRInput.Button.One)){
    OVRHaptics.RightChannel.Mix (myHapticsClip);
    }
    }
    }

    Then create a gameobject, slap the script on it and make sure to drag an audio file in the inspector onto the myAudioClip variable.