public void OnControllerDrop() { // Checks if we have something to drop if (currentInteractible) { if (currentInteractible.CompareTag("ClippingPlaneInteractible") || currentInteractible.CompareTag("ClippingPlaneInteractible2")) { currentInteractible.transform.parent.parent.parent.GetComponent <Rigidbody>().useGravity = false; currentInteractible.transform.parent.parent.parent.GetComponent <Rigidbody>().isKinematic = true; } else if (currentInteractible.CompareTag("ClippingBoxInteractible")) { currentInteractible.transform.parent.GetComponent <Rigidbody>().useGravity = false; currentInteractible.transform.parent.GetComponent <Rigidbody>().isKinematic = true; } else if (currentInteractible.CompareTag("CubeInteractible")) { Rigidbody targetBody = currentInteractible.transform.parent.GetComponent <Rigidbody>(); targetBody.velocity = pose.GetVelocity(); targetBody.angularVelocity = pose.GetAngularVelocity(); } // Detaches the current interactible object to our motion controller joint.connectedBody = null; // Clear the memory of variables currentInteractible.activeController = null; currentInteractible = null; } }
private CustomizedInteractible GetNearestInteractible() { CustomizedInteractible nearest = null; float minDistance = float.MaxValue; float distance = 0.0f; foreach (CustomizedInteractible interactible in contactInteractibles) { distance = (interactible.transform.position - transform.position).sqrMagnitude; if (distance < minDistance) { minDistance = distance; nearest = interactible; } } return(nearest); }
public void OnControllerDrag() { // Get the nearest interactible object currentInteractible = GetNearestInteractible(); // Checks if the function returns a value if (currentInteractible) { if (currentInteractible.CompareTag("ClippingPlaneInteractible") || currentInteractible.CompareTag("ClippingPlaneInteractible2")) { currentInteractible.transform.parent.parent.parent.GetComponent <Rigidbody>().useGravity = true; currentInteractible.transform.parent.parent.parent.GetComponent <Rigidbody>().isKinematic = false; // Moves the position of the interactible object to the motion controller one Vector3.MoveTowards(transform.position, currentInteractible.transform.parent.parent.parent.position, Time.deltaTime); // Attaches the interactible object to the motion controller via the sphere Rigidbody targetBody = currentInteractible.transform.parent.parent.parent.GetComponent <Rigidbody>(); joint.connectedBody = targetBody; // Indicates that the active controller is this one currentInteractible.activeController = this; } else if (currentInteractible.CompareTag("ClippingBoxInteractible") || currentInteractible.CompareTag("CubeInteractible")) { currentInteractible.transform.parent.GetComponent <Rigidbody>().useGravity = true; currentInteractible.transform.parent.GetComponent <Rigidbody>().isKinematic = false; // Moves the position of the interactible object to the motion controller one Vector3.MoveTowards(transform.position, currentInteractible.transform.parent.position, Time.deltaTime); // Attaches the interactible object to the motion controller via the sphere Rigidbody targetBody = currentInteractible.transform.parent.GetComponent <Rigidbody>(); joint.connectedBody = targetBody; // Indicates that the active controller is this one currentInteractible.activeController = this; } } }