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.

UPDATE: Getting the Touch haptics to activate? SOLVED

the5soulsthe5souls Posts: 21
Brain Burst
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!
Tagged:

Best Answer

Answers

  • WelbyWelby Posts: 1,065 Oculus Start Member
    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
  • the5soulsthe5souls Posts: 21
    Brain Burst
    Hmm... and you also dragged an audio clip into the "myAudioClip" section in your object Unity?
  • willtionvonwilltionvon Posts: 3
    NerveGear
    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?
  • omtronomtron Posts: 23
    Brain Burst
    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.
Sign In or Register to comment.