Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1.  public class ControllerHaptics : MonoBehaviour {
  2.  
  3.      SteamVR_TrackedObject trackedObject;
  4.      SteamVR_Controller.Device device;
  5.  
  6.      GameObject[] soundSpheres;
  7.  
  8.      // Use this for initialization
  9.      void Start()
  10.      {
  11.          trackedObject = GetComponent<SteamVR_TrackedObject>();
  12.          device = SteamVR_Controller.Input((int)trackedObject.index);
  13.  
  14.          soundSpheres = GameObject.FindGameObjectsWithTag("Grabbable");
  15.      }
  16.  
  17.      //Update is called once per frame
  18.      void Update()
  19.      {
  20.          FireHapticsBasedOnDistance();
  21.      }
  22.  
  23.      private void FireHapticsBasedOnDistance()
  24.      {
  25.          foreach (GameObject soundSp in soundSpheres)
  26.          {
  27.              // controller approaches Sound Sphere
  28.              if ((transform.position - soundSp.transform.position).magnitude < 0.5f) //if the distance between the controller and the Sound Sphere is less than 0.5 then:
  29.              {
  30.                  //we have found a Sound Sphere close to a controller
  31.                  device.TriggerHapticPulse(600); // <------- this value should increase as the above magnitude decreases. note that this value is a "ushort" value and probably needs to be converted?
  32.  
  33.                  break;
  34.              }
  35.          }
  36.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement