private void GrabObject() { objectInHand = collidingObject; collidingObject = null; Debug.Log("Grab" + objectInHand); // Join object to the vive controller. var joint = AddFixedJoint(); joint.connectedBody = objectInHand.GetComponent <Rigidbody>(); // Get script. objectScript = objectInHand.GetComponent <ObjSpawnable>(); if (objectScript) { objectScript.CatchObject(); } }
private void ReleaseObject() { Debug.Log("Grab" + objectInHand); FixedJoint joint = GetComponent <FixedJoint>(); // break joint. Pass velocity of the controller to the object. if (joint) { joint.connectedBody = null; Destroy(joint); objectInHand.GetComponent <Rigidbody>().velocity = Device.velocity * objectScript.forceScale; objectInHand.GetComponent <Rigidbody>().angularVelocity = Device.angularVelocity; } // Free object and his script. objectInHand = null; if (objectScript) { objectScript.ReleaseObject(); objectScript = null; } }