private void Pickup() { m_CurrentInteractable = GetNearestInteractable(); if (!m_CurrentInteractable) { return; } if (m_CurrentInteractable.m_ActiveHand) { m_CurrentInteractable.m_ActiveHand.Drop(); } if (m_CurrentInteractable != null) { m_CurrentInteractable.ApplyTransform(transform); m_CurrentInteractable.m_ActiveHand = this; Rigidbody rigidbody = m_CurrentInteractable.GetComponent <Rigidbody>(); m_joint.connectedBody = rigidbody; } m_CurrentInteractable.m_ActiveHand = this; }
private void Drop() { if (!m_CurrentInteractable) { return; } //Rigidbody rigidbody = m_CurrentInteractable.GetComponent<Rigidbody>(); //rigidbody.velocity = m_pose.GetVelocity(); //rigidbody.angularVelocity = m_pose.GetAngularVelocity(); m_CurrentInteractable.m_ActiveHand = null; m_CurrentInteractable = null; m_joint.connectedBody = null; }
private ShiInteractable GetNearestInteractable() { ShiInteractable nearest = null; float minDistance = float.MaxValue; float distance = .0f; foreach (ShiInteractable interactable in m_CurrentInteractables) { distance = (interactable.transform.position - transform.position).sqrMagnitude; if (distance < minDistance) { minDistance = distance; nearest = interactable; } } return(nearest); }