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.

Touch vibration in unity(C#)?

TrevJTTrevJT Posts: 44
Brain Burst

I just keep crashing my game trying out different ways to enable touch vibration, does anyone know how to do it correctly in Unity 5?

Start()  HapticsClip = new OVRHapticsClip(VibeClip);

RHit()   OVRHaptics.RightChannel.Preempt(HapticsClip);

^ In this example VibeClip is less than a second long audio clip

^This crashes unity. so does trying 

OVRHaptics.Channels[1].Mix(new OVRHapticsClip(VibeClip));


  • vrdavebvrdaveb Posts: 1,596 Oculus Staff
    Here's an example you can use to play a sound and corresponding vibration on contact.

    using System.Collections.Generic;
    using UnityEngine;
    public class PhysicsSound : MonoBehaviour
    	public bool useHaptics = false;
    	public bool useSound = true;
    	public OVRInput.Controller controller;
    	private AudioSource cachedSource;
    	private OVRHapticsClip hapticsClip;
    	private float hapticsClipLength;
    	private float hapticsTimeout;
    	void OnTriggerEnter(Collider c)
    		if (useHaptics)
    		if (useSound)
    	void OnCollisionEnter(Collision c)
    		if (useHaptics)
    		if (useSound)
    	void PlayHaptics(Collider c)
    		var source = c.GetComponent<AudioSource>();
    		if (source == null)
    		if (source != cachedSource)
    			hapticsClip = new OVRHapticsClip (source.clip);
    			hapticsClipLength = source.clip.length;
    			cachedSource = source;
    		if (Time.time < hapticsTimeout)
    		hapticsTimeout = Time.time + hapticsClipLength;
    		if (controller == OVRInput.Controller.LTouch)
    	void PlaySound(Collider c)
    		var source = c.GetComponent<AudioSource>();
    		if (source && !source.isPlaying)

  • sirine.jaballasirine.jaballa Posts: 1

    bonjour a tous ,
    Salut, je débute dans le code, et je voulais savoir comment on écrit un script une action de (vibration ) qui dure par exemple demi seconde, et qui peut être répétée, après un délai d'une seconde?

    avec Unity codé par c#

    j'attend votre réponse ,merci d'avance

  • jphilippjphilipp Posts: 28
    Brain Burst
    VRDave, thanks for the code sample, and strange, I don't get any vibration when I try. I'm on all latest Unity & Oculus sdk, did something change in the meantime or am I doing something wrong?
    - Anyland dev -
Sign In or Register to comment.