vr controller control script
Hi
I'm trying to learn my way to interact with a vr scene (using vive and unity 5) so I can create my own interactions
I was starting with the "simple" tricik of picking a damn cube off the ground, but the current script I've found doesn't work in my case
public class ControllerInteraction : MonoBehaviour {
 private Valve.VR.EVRButtonId gripButton = Valve.VR.EVRButtonId.k_EButton_Grip;
 private Valve.VR.EVRButtonId triggerButton = Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger;
 private SteamVR_Controller.Device controller { get { return SteamVR_Controller.Input((int)trackedObj.index); } }
 private SteamVR_TrackedObject trackedObj;
 private GameObject pickup;
 void Start() {
     trackedObj = GetComponent<SteamVR_TrackedObject>();
 }
 void Update() {
     if (controller == null)
     {
         Debug.Log("Controller not initialized");
         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;
     }
 }
 private void OnTriggerEnter(Collider other)
 {
     pickup = GetComponent<Collider>().gameObject;        
 }
 private void OnTriggerExit(Collider other)
 {
     pickup = null;
 }
}
It should pick up the object by making it a child of the controller, but for some reason it moves the controller out of the SteamVR parent when I try to grab something
What am I doing wrong here?
Your answer
 
 
             Follow this Question
Related Questions
pressing/turning something in VR to do stuff 0 Answers
Steam Leaderboards in Unity, upload time since level load 0 Answers
How to get the velocity of the controllers ( Steam VR 2.2) ? 1 Answer
Making KeyCodes Equal to Touch Triggers? 1 Answer
Hit UI elements with raycast in VR,How to make a raycast hit a UI object in VR 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                