private void initializeGrab(Hand hand) { int controller = (int)hand; // Calculate Quaternion distance between the head to the controller and the head to the object Vector3 actualHeadPos = CalcActualHeadPos(); Quaternion headToController = Quaternion.LookRotation(controllers[controller].position - actualHeadPos); if (controller == 1) { currSelectedRObj = currRHandObservedObj; // Quaternion headToObject = Quaternion.LookRotation(currSelectedRObj.transform.position - hmd.position); Quaternion headToObject = Quaternion.LookRotation(currSelectedRObj.transform.position - actualHeadPos); rHandDiffQuat = headToObject * Quaternion.Inverse(headToController); //Save the distances from the hand to the object and the hand from the headset. rHandObjDist = Vector3.Distance(controllers[controller].position, currSelectedRObj.transform.position); // initRHandDistFromHmd = Vector3.Distance(controllers[controller].position, hmd.position); initRHandDistFromHmd = Vector3.Distance(controllers[controller].position, actualHeadPos); currSelectedRObj.GetComponent <Rigidbody>().velocity = Vector3.zero; } else { currSelectedLObj = currLHandObservedObj; // Quaternion headToObject = Quaternion.LookRotation(currSelectedLObj.transform.position - hmd.position); Quaternion headToObject = Quaternion.LookRotation(currSelectedLObj.transform.position - actualHeadPos); lHandDiffQuat = headToObject * Quaternion.Inverse(headToController); //Save the distances from the hand to the object and the hand from the headset. lHandObjDist = Vector3.Distance(controllers[controller].position, currSelectedLObj.transform.position); // initLHandDistFromHmd = Vector3.Distance(controllers[controller].position, hmd.position); initLHandDistFromHmd = Vector3.Distance(controllers[controller].position, actualHeadPos); currSelectedLObj.GetComponent <Rigidbody>().velocity = Vector3.zero; } }
private bool CheckMaterial() { InteractableObject interactableObject = manipulatable.GetComponent <InteractableObject>(); if (interactableObject == null || matter == null) { return(false); } if (interactableObject.matter.name == matter.name) { return(true); } else { return(false); } }
private void releasePushWithObj(Hand hand) { int controller = (int)hand; if (controller == 1) { if (currSelectedRObj == null) { return; } //Direction should be away from the player //Vector3 direction = currSelectedRObj.transform.position - hmd.position; Vector3 direction = controllers[controller].forward; direction.Normalize(); //Magnitude should be based on how long the button was held float chargeTime = Time.time - startRChargeTime; chargeTime = Mathf.Min(chargeTime, 2f); currSelectedRObj.GetComponent <Rigidbody>().AddForce(direction * (1000f + (chargeTime * 1000f))); currSelectedRObj.gameObject.GetComponent <Rigidbody>().useGravity = true; currSelectedRObj = null; } else { if (currSelectedLObj == null) { return; } //Direction should be away from the player //Vector3 direction = currSelectedLObj.transform.position - hmd.position; Vector3 direction = controllers[controller].forward; direction.Normalize(); //Magnitude should be based on how long the button was held float chargeTime = Time.time - startLChargeTime; chargeTime = Mathf.Min(chargeTime, 2f); currSelectedLObj.GetComponent <Rigidbody>().AddForce(direction * (1000f + (chargeTime * 1000f))); currSelectedLObj.gameObject.GetComponent <Rigidbody>().useGravity = true; currSelectedLObj = null; } }