Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using Valve.VR;
- using System;
- public class WandController : MonoBehaviour {
- private Valve.VR.EVRButtonId gripButton = Valve.VR.EVRButtonId.k_EButton_Grip; //Essentially this is accessing
- //SteamVR_TrackedObject.cs and telling our script
- //and defining it here.
- private Valve.VR.EVRButtonId triggerButton = Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger;
- private Valve.VR.EVRButtonId Touchpad = Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad;
- private SteamVR_Controller.Device controller { get { return SteamVR_Controller.Input((int)trackedObj.index); } }
- private SteamVR_TrackedObject trackedObj;
- SteamVR_Controller.Device device;
- SteamVR_TrackedObject MotionControl;
- Vector2 touchpadLoc; //Touchpad location.
- private Vector2 Up = new Vector2(0, 1);
- private GameObject pickup;
- // Use this for initialization
- void Start ()
- {
- MotionControl = gameObject.GetComponent<SteamVR_TrackedObject>();
- trackedObj = GetComponent<SteamVR_TrackedObject>();
- }
- // Update is called once per frame
- void Update()
- {
- if (controller == null)
- {
- Debug.Log("Controller not initalized");
- return;
- }
- if (controller.GetPressDown(gripButton) && pickup != null)
- {
- pickup.transform.parent = this.transform;
- pickup.GetComponent<Rigidbody>().isKinematic = true;
- }
- if (controller.GetPressUp(gripButton) && pickup != null)
- {
- pickup.transform.parent = null;
- pickup.GetComponent<Rigidbody>().isKinematic = false;
- Debug.Log("Grip button was unpressed");
- }
- device = SteamVR_Controller.Input((int)controller.index);
- //If finger is on touchpad
- if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
- {
- //Read the touchpad values
- touchpadLoc = device.GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad);
- //Debug.Log(touchpadLoc);
- double targetUpXOld = 0.0; //Old target up value.
- float targetUpX = (float)targetUpXOld;
- double targetUpYOld = 0.8;
- float targetUpY = (float)targetUpYOld;
- Vector2 targetUp = new Vector2(targetUpX, targetUpY);
- if (Vector2.Distance(touchpadLoc, targetUp) < .15) //If the distance between finger (touchpadLoc) and the up zone (targetUp) is more than 0 do something.
- {
- Debug.Log("Up position met.");
- }
- double targetDownXOld = -0.0; //Old target up value.
- float targetDownX = (float)targetUpXOld;
- double targetDownYOld = -0.8;
- float targetDownY = (float)targetUpYOld;
- Vector2 targetDown = new Vector2(targetUpX, targetUpY);
- if (Vector2.Distance(touchpadLoc, targetDown) > .15)
- {
- Debug.Log("Down position met.");
- }
- }
- }
- private void OnTriggerEnter(Collider collider)
- {
- pickup = collider.gameObject;
- }
- private void OnTriggerExit(Collider collider)
- {
- pickup = null;
- }
- }
Add Comment
Please, Sign In to add comment