Exemplo n.º 1
0
        /// <summary>
        /// When the grab begins, create the joint that will held the object to the grabber.
        /// The Anchor points of the Joint specify the offset to the grabber here.
        /// If a custom joint was provided, duplicate it and mimic its values, if not it will use a fixe joint.
        /// </summary>
        /// <param name="hand">The grabber hand</param>
        /// <param name="grabPoint">The collider selected for the grab.</param>
        public override void GrabBegin(BaseGrabber hand, Collider grabPoint)
        {
            base.GrabBegin(hand, grabPoint);

            if (immovable)
            {
                return;
            }

            Joint joint = null;

            if (customJoint != null)
            {
                joint = CloneJoint(customJoint, this.gameObject) as Joint;
            }
            else
            {
                joint = CreateDefaultJoint();
            }

            joint.connectedBody = hand.GetComponent <Rigidbody>();
            joint.autoConfigureConnectedAnchor = false;
            joint.anchor          = joint.transform.InverseTransformPoint(hand.transform.position);
            joint.connectedAnchor = Vector3.zero;

            RemoveJoint(hand);
            _joints.Add(hand, joint);

            _body.isKinematic = false;
        }
Exemplo n.º 2
0
 private void RemoveJoint(BaseGrabber hand)
 {
     if (_joints.TryGetValue(hand, out Joint joint))
     {
         _joints.Remove(hand);
         Destroy(joint);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Restore the GrabStart values when object is released and throw it if not being held.
 /// </summary>
 /// <param name="hand"></param>
 /// <param name="linearVelocity"></param>
 /// <param name="angularVelocity"></param>
 public virtual void GrabEnd(BaseGrabber hand, Vector3 linearVelocity, Vector3 angularVelocity)
 {
     if (_grabbedBy.Contains(hand))
     {
         _grabbedBy.Remove(hand);
     }
     if (_grabbedBy.Count == 0)
     {
         _body.isKinematic     = _isKinematic;
         _body.velocity        = linearVelocity;
         _body.angularVelocity = angularVelocity;
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// When the object is grabbed, record the grabber and disable physics.
        /// </summary>
        /// <param name="hand">Grabber hand.</param>
        /// <param name="grabPoint">Collider being held.</param>
        public virtual void GrabBegin(BaseGrabber hand, Collider grabPoint)
        {
            if (!MultiGrab)
            {
                foreach (var grabber in _grabbedBy.ToList())
                {
                    grabber.OffhandGrabbed(this);
                }
                _grabbedBy.Clear();
            }

            if (!_grabbedBy.Contains(hand))
            {
                _grabbedBy.Add(hand);
            }
            _body.isKinematic = true;
        }
Exemplo n.º 5
0
 /// <summary>
 /// When the object is released, remove the joint associated to the hand.
 /// </summary>
 /// <param name="hand">Hand that released the object.</param>
 /// <param name="linearVelocity">Linear velocity of the throw.</param>
 /// <param name="angularVelocity">Angular velocity of the throw.</param>
 public override void GrabEnd(BaseGrabber hand, Vector3 linearVelocity, Vector3 angularVelocity)
 {
     RemoveJoint(hand);
     base.GrabEnd(hand, linearVelocity, angularVelocity);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Clear all grabs on this object.
 /// </summary>
 public void UnsuscribeGrabber()
 {
     BaseGrabber.ClearAllGrabs(this);
 }