SHARE
TWEET

Untitled

a guest Oct 17th, 2017 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Wandcontroller : MonoBehaviour
  6. {
  7.  
  8.     private Valve.VR.EVRButtonId gripButton = Valve.VR.EVRButtonId.k_EButton_Grip;
  9.     private Valve.VR.EVRButtonId triggerButton = Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger;
  10.     private SteamVR_Controller.Device controller { get { return SteamVR_Controller.Input((int)trackedObj.index); } }
  11.     private SteamVR_TrackedObject trackedObj;
  12.  
  13.     private GameObject pickup;
  14.  
  15.     public GameObject cameraRig;
  16.  
  17.     Vector3 gripPosition;
  18.     Vector3 difference;
  19.     Vector3 cameraRigPosition;
  20.     Vector3 temp;
  21.  
  22.     Vector3 playerResetDifference;
  23.  
  24.     bool isClimbing;
  25.  
  26.     // Use this for initialization
  27.     void Start()
  28.     {
  29.         trackedObj = GetComponentInParent<SteamVR_TrackedObject>();
  30.  
  31.     }
  32.  
  33.     private void OnTriggerEnter(Collider collider)
  34.     {
  35.         if (collider.tag == "bar")
  36.         {
  37.             pickup = collider.gameObject;
  38.  
  39.         }
  40.  
  41.  
  42.     }
  43.  
  44.     private void OnTriggerExit(Collider collider)
  45.     {
  46.       //  if (collider.tag == "bar")
  47.           //  pickup = null;
  48.     }
  49.    
  50.     // Update is called once per frame
  51.     void Update()
  52.     {
  53.  
  54.         if (controller == null)
  55.         {
  56.             Debug.Log("controller not found");
  57.             return;
  58.         }
  59.  
  60.         if (controller.GetPressDown(gripButton) && pickup != null)
  61.         {
  62.             Debug.Log("Success");
  63.             gripPosition = transform.position;
  64.             cameraRigPosition = cameraRig.transform.position;
  65.             isClimbing = true;
  66.             Debug.Log(gripPosition);
  67.  
  68.         }
  69.         if (controller.GetPressUp(gripButton))
  70.         {
  71.             Debug.Log ("cameraRigPosition: " +cameraRigPosition);
  72.             Debug.Log ("camera transform: " +cameraRig.transform.position);
  73.  
  74.             temp = cameraRigPosition;
  75.             temp.y = cameraRig.transform.position.y;
  76.  
  77.             playerResetDifference = temp - cameraRig.transform.position;
  78.             Debug.Log ("Player reset: " + playerResetDifference);
  79.  
  80.             //resetting player and camera
  81.             //transform.localPosition -= playerResetDifference;
  82.             cameraRig.transform.position = temp;
  83.  
  84.  
  85.  
  86.             isClimbing = false;
  87.             pickup = null;
  88.         }
  89.  
  90.         if (isClimbing)
  91.         {
  92.             Debug.Log("is climbing");
  93.             difference = (gripPosition - transform.position);
  94.  
  95.             cameraRig.transform.position += difference;
  96.         }
  97.     }
  98.  
  99.  
  100. }
RAW Paste Data
Top