Exemplo n.º 1
0
        /// <summary>
        /// Try to grab items
        /// </summary>
        private void UpdateGrabObjects()
        {
            //Debug.Log(HandData.GetCloseValue(DeviceType));
            if (_grabbedItem != null || HandData.GetCloseValue(DeviceType) == CloseValue.Fist)
            {
                return;
            }
            // Always try to grab a item when the user is making a fist
            if (HandData.FirstJointAverage(DeviceType) > 0.32f && _physicsHand.AmountOfCollidingObjects() > 0)
            {
                foreach (var rb in TriggerBinder.CollidingInteractables)
                {
                    GrabItem(rb);
                }
            }


            if (_physicsHand.IsThumbColliding && _physicsHand.AmountOfCollidingObjects() > 1 && HandData.FirstJointAverage(DeviceType) > 0.07f)
            {
                foreach (var rb in TriggerBinder.CollidingInteractables)
                {
                    GrabItem(rb);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Try to grab the given rigidbody
        /// </summary>
        /// <param name="interactable"></param>
        private void GrabItem(Interactable interactable)
        {
            if (_grabbedItem != null)
            {
                return;
            }
            PhysicsObject physicsObject = null;

            if (!PhysicsManager.Instance.GetPhysicsObject(interactable.gameObject, out physicsObject) || !interactable.IsGrabbable)
            {
                return;
            }

            _grabbedItem = interactable;
            _grabbedItem.Attach(_physicsHand.HandRigidbody, this);

            _averageOnGrab = HandData.FirstJointAverage(DeviceType) - AverageGrabOffset;

            // Ignore collision between the grabbed object and the grabbing hand
            IgnoreCollision(physicsObject.Rigidbody, true);

            if (OnItemGrabbed != null)
            {
                OnItemGrabbed(_grabbedItem.gameObject, DeviceType);
            }
            VibrateHand();

            if (_grabbedItem.AttachHandToItem)
            {
                _physicsHand.EnableRotation(false);
            }
            HandRigidbody.centerOfMass = HandRigidbody.transform.InverseTransformPoint(_grabbedItem.transform.position);
        }
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyUp(KeyCode.Space))
     {
         Debug.Log("Average Value Left" + handData.Average(device_type_t.GLOVE_LEFT).ToString());
         Debug.Log("Average Knuckle Left" + handData.FirstJointAverage(device_type_t.GLOVE_LEFT).ToString());
     }
 }