Ejemplo n.º 1
0
 public void Release()
 {
     if (IsGrabbing)
     {
         IsGrabbing = false;
         Debug.Log("Released " + GrabbedObject.name);
         if (CurrentlyActiveJoint.connectedBody != null)
         {
             CurrentlyActiveJoint.connectedBody.angularVelocity = _controller.Controller.angularVelocity;
             CurrentlyActiveJoint.connectedBody.velocity        = _controller.Controller.velocity;
             CurrentlyActiveJoint.connectedBody = null;
         }
         GrabbedObject.Release(this);
         GrabbedObject     = null;
         _grabbedMagnitude = 0;
         _controller.HandController.SetGrabState(false, HandStateEnum.Free);
     }
 }
Ejemplo n.º 2
0
        private void TryGrab(TrackedController sender, float TriggerValue)
        {
            if (IsGrabbing)
            {
                Debug.Log("Grabber is Grabbing already, something went wrong");
                return;
            }

            var toGrab = Scanner.GetClosestInterractableObject();

            if (toGrab != null)
            {
                var grabbedObject = toGrab.GetComponentInParent <GrabbableObject>();
                if (grabbedObject != null && grabbedObject.CurrentGrabber == null)
                {
                    GrabbedObject = grabbedObject;
                    IsGrabbing    = true;
                    GrabbedObject.Grab(this);
                    Debug.Log("Grabbed " + GrabbedObject.name);
                    if (!grabbedObject.UsesFakeGrab)
                    {
                        if (grabbedObject.UseSpring)
                        {
                            CurrentlyActiveJoint = SpringJoint;
                        }
                        else
                        {
                            CurrentlyActiveJoint = ConfigurableJoint;
                        }
                        CurrentlyActiveJoint.connectedBody = GrabbedObject.GetComponentInParent <Rigidbody>();
                        _grabbedMagnitude = (CurrentlyActiveJoint.transform.position - CurrentlyActiveJoint.connectedBody.transform.position).sqrMagnitude;
                    }
                    _controller.HandController.SetGrabState(true, GrabbedObject.ActivationHandState);
                }
            }
        }