Ejemplo n.º 1
0
        //-------------------------------------------------
        private void OnDetachedFromHand(Hand hand)
        {
            attached = false;

            onDetachFromHand.Invoke();

            hand.HoverUnlock(null);

            Rigidbody rb = GetComponent <Rigidbody>();

            rb.isKinematic   = false;
            rb.interpolation = RigidbodyInterpolation.Interpolate;

            Vector3 position        = Vector3.zero;
            Vector3 velocity        = Vector3.zero;
            Vector3 angularVelocity = Vector3.zero;

            if (hand.controller == null)
            {
                velocityEstimator.FinishEstimatingVelocity();
                velocity        = velocityEstimator.GetVelocityEstimate();
                angularVelocity = velocityEstimator.GetAngularVelocityEstimate();
                position        = velocityEstimator.transform.position;
            }
            else
            {
                velocity        = Player.instance.trackingOriginTransform.TransformVector(hand.controller.velocity);
                angularVelocity = Player.instance.trackingOriginTransform.TransformVector(hand.controller.angularVelocity);
                position        = hand.transform.position;
            }

            Vector3 r = transform.TransformPoint(rb.centerOfMass) - position;

            rb.velocity        = velocity + Vector3.Cross(angularVelocity, r);
            rb.angularVelocity = angularVelocity;

            // Make the object travel at the release velocity for the amount
            // of time it will take until the next fixed update, at which
            // point Unity physics will take over
            float timeUntilFixedUpdate = (Time.fixedDeltaTime + Time.fixedTime) - Time.time;

            transform.position += timeUntilFixedUpdate * velocity;
            float   angle = Mathf.Rad2Deg * angularVelocity.magnitude;
            Vector3 axis  = angularVelocity.normalized;

            transform.rotation *= Quaternion.AngleAxis(angle * timeUntilFixedUpdate, axis);
        }
Ejemplo n.º 2
0
        //-------------------------------------------------
        private void HandHoverUpdate(Hand hand)
        {
            if (hand.GetStandardInteractionButtonDown())
            {
                hand.HoverLock(GetComponent <Interactable>());

                initialMappingOffset = linearMapping.value - CalculateLinearMapping(hand.transform);
                sampleCount          = 0;
                mappingChangeRate    = 0.0f;
            }

            if (hand.GetStandardInteractionButtonUp())
            {
                hand.HoverUnlock(GetComponent <Interactable>());

                CalculateMappingChangeRate();
            }

            if (hand.GetStandardInteractionButton())
            {
                UpdateLinearMapping(hand.transform);
            }
        }