/// <summary>
 /// Dettach this object from the given hand
 /// </summary>
 /// <param name="hand"></param>
 public override void Detach(ObjectGrabber hand)
 {
     base.Detach(hand);
     Rigidbody.useGravity  = GravityWhenReleased;
     Rigidbody.isKinematic = KinematicWhenReleased;
     Destroy(Connection);
     _target = null;
     if (HighlightWhenGrabbed)
     {
         ActivateOutline(false);
     }
 }
        /// <summary>
        /// Attach this interactable to the given rigidbody
        /// </summary>
        /// <param name="connectedBody"></param>
        /// <param name="attachedJoint"></param>
        public virtual void Attach(Rigidbody connectedBody, ObjectGrabber hand)
        {
            if (Hand != null)
            {
                Hand.ReleaseItem();
            }
            Hand = hand;

            if (OnGrabbed != null)
            {
                OnGrabbed.Invoke();
            }
        }
        /// <summary>
        /// Detach the given joint from this interactable
        /// </summary>
        /// <param name="connection"></param>
        public virtual void Detach(ObjectGrabber hand)
        {
            var tempHand = Hand;

            if (Hand == null)
            {
                return;
            }

            Hand = null;
            tempHand.ReleaseItem();
            tempHand = null;
            if (OnReleased != null)
            {
                OnReleased.Invoke();
            }
        }
        public override void Attach(Rigidbody connectedBody, ObjectGrabber hand)
        {
            base.Attach(connectedBody, hand);
            Rigidbody.isKinematic = false;

            if (!AttachHandToItem)
            {
                _target         = connectedBody;
                _offsetPosition = connectedBody.transform.InverseTransformPoint(Rigidbody.transform.position);
                _offsetRotation = Quaternion.Inverse(_target.transform.rotation) * transform.rotation;
            }

            else
            {
                // Destroy the old joint
                Destroy(Connection);

                // Add a fixed joint to the object
                ConfigurableJoint rotationJoint = connectedBody.gameObject.AddComponent <ConfigurableJoint>();

                Connection = rotationJoint;

                rotationJoint.xMotion = ConfigurableJointMotion.Locked;
                rotationJoint.yMotion = ConfigurableJointMotion.Locked;
                rotationJoint.zMotion = ConfigurableJointMotion.Locked;

                rotationJoint.angularXMotion = ConfigurableJointMotion.Locked;
                rotationJoint.angularYMotion = ConfigurableJointMotion.Locked;
                rotationJoint.angularZMotion = ConfigurableJointMotion.Locked;

                Connection.connectedBody = Rigidbody;
            }

            Rigidbody.useGravity = GravityWhenGrabbed;

            if (HighlightWhenGrabbed)
            {
                ActivateOutline(true);
            }
        }