Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ControllerHaptics : MonoBehaviour {
- SteamVR_TrackedObject trackedObject;
- SteamVR_Controller.Device device;
- GameObject[] soundSpheres;
- // Use this for initialization
- void Start()
- {
- trackedObject = GetComponent<SteamVR_TrackedObject>();
- device = SteamVR_Controller.Input((int)trackedObject.index);
- soundSpheres = GameObject.FindGameObjectsWithTag("Grabbable");
- }
- //Update is called once per frame
- void Update()
- {
- FireHapticsBasedOnDistance();
- }
- private void FireHapticsBasedOnDistance()
- {
- foreach (GameObject soundSp in soundSpheres)
- {
- // controller approaches Sound Sphere
- 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:
- {
- //we have found a Sound Sphere close to a controller
- 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?
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement