Пример #1
0
        public virtual void GetReleaseVelocities(Hand hand, out Vector3 velocity, out Vector3 angularVelocity)
        {
            if (hand.noSteamVRFallbackCamera && releaseVelocityStyle != ReleaseStyle.NoChange)
            {
                releaseVelocityStyle = ReleaseStyle.ShortEstimation; // only type that works with fallback hand is short estimation.
            }
            switch (releaseVelocityStyle)
            {
            case ReleaseStyle.ShortEstimation:
                velocityEstimator.FinishEstimatingVelocity();
                velocity        = velocityEstimator.GetVelocityEstimate();
                angularVelocity = velocityEstimator.GetAngularVelocityEstimate();
                break;

            case ReleaseStyle.AdvancedEstimation:
                hand.GetEstimatedPeakVelocities(out velocity, out angularVelocity);
                break;

            case ReleaseStyle.GetFromHand:
                velocity        = hand.GetTrackedObjectVelocity(releaseVelocityTimeOffset);
                angularVelocity = hand.GetTrackedObjectAngularVelocity(releaseVelocityTimeOffset);
                break;

            default:
            case ReleaseStyle.NoChange:
                velocity        = rigidbody.velocity;
                angularVelocity = rigidbody.angularVelocity;
                break;
            }

            if (releaseVelocityStyle != ReleaseStyle.NoChange)
            {
                velocity *= scaleReleaseVelocity;
            }
        }
Пример #2
0
        public virtual void GetReleaseVelocities(Hand hand, out Vector3 velocity, out Vector3 angularVelocity)
        {
            switch (releaseVelocityStyle)
            {
            case ReleaseStyle.ShortEstimation:
                velocityEstimator.FinishEstimatingVelocity();
                velocity        = velocityEstimator.GetVelocityEstimate();
                angularVelocity = velocityEstimator.GetAngularVelocityEstimate();
                break;

            case ReleaseStyle.AdvancedEstimation:
                hand.GetEstimatedPeakVelocities(out velocity, out angularVelocity);
                break;

            case ReleaseStyle.GetFromHand:
                velocity        = hand.GetTrackedObjectVelocity(releaseVelocityTimeOffset);
                angularVelocity = hand.GetTrackedObjectAngularVelocity(releaseVelocityTimeOffset);
                break;

            default:
            case ReleaseStyle.NoChange:
                velocity        = rigidbody.velocity;
                angularVelocity = rigidbody.angularVelocity;
                break;
            }

            if (releaseVelocityStyle != ReleaseStyle.NoChange)
            {
                velocity *= scaleReleaseVelocity;
            }
        }
Пример #3
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();
                //scale the velocity
                velocity        = velocityEstimator.GetVelocityEstimate() * scaleVelocity;
                angularVelocity = velocityEstimator.GetAngularVelocityEstimate() * scaleVelocity;

                position = velocityEstimator.transform.position;
            }
            else
            {
                velocity        = Player.instance.trackingOriginTransform.TransformVector(hand.controller.velocity);
                angularVelocity = Player.instance.trackingOriginTransform.TransformVector(hand.controller.angularVelocity);

                //adjust for scale
                angularVelocity = angularVelocity * scaleVelocity;


                // Vector3 v = hand.controller.angularVelocity;
                // Debug.Log(v +" "+Player.instance.trackingOriginTransform.TransformVector(v));

                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);
        }
Пример #4
0
        public virtual void GetReleaseVelocities(Hand hand, out Vector3 velocity, out Vector3 angularVelocity)
        {
            if (hand.noSteamVRFallbackCamera && releaseVelocityStyle != ReleaseStyle.NoChange)
            {
                releaseVelocityStyle = ReleaseStyle.ShortEstimation; // only type that works with fallback hand is short estimation.
            }
            switch (releaseVelocityStyle)
            {
            case ReleaseStyle.ShortEstimation:
                if (velocityEstimator != null)
                {
                    velocityEstimator.FinishEstimatingVelocity();
                    velocity        = velocityEstimator.GetVelocityEstimate();
                    angularVelocity = velocityEstimator.GetAngularVelocityEstimate();
                }
                else
                {
                    Debug.LogWarning("[SteamVR Interaction System] Throwable: No Velocity Estimator component on object but release style set to short estimation. Please add one or change the release style.");

                    velocity        = rigidbody.velocity;
                    angularVelocity = rigidbody.angularVelocity;
                }
                break;

            case ReleaseStyle.AdvancedEstimation:
                hand.GetEstimatedPeakVelocities(out velocity, out angularVelocity);
                break;

            case ReleaseStyle.GetFromHand:
                velocity        = hand.GetTrackedObjectVelocity(releaseVelocityTimeOffset);
                angularVelocity = hand.GetTrackedObjectAngularVelocity(releaseVelocityTimeOffset);
                break;

            default:
            case ReleaseStyle.NoChange:
                velocity        = rigidbody.velocity;
                angularVelocity = rigidbody.angularVelocity;
                break;
            }

            if (releaseVelocityStyle != ReleaseStyle.NoChange)
            {
                float scaleFactor = 1.0f;
                if (scaleReleaseVelocityThreshold > 0)
                {
                    scaleFactor = Mathf.Clamp01(scaleReleaseVelocityCurve.Evaluate(velocity.magnitude / scaleReleaseVelocityThreshold));
                }

                velocity *= (scaleFactor * scaleReleaseVelocity);
            }
        }
Пример #5
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;

            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);

            Invoke("StartFetching", 1);
        }
Пример #6
0
        public virtual void GetReleaseVelocities(Hand hand, out Vector3 velocity, out Vector3 angularVelocity)
        {
            switch (releaseVelocityStyle)
            {
            case ReleaseStyle.ShortEstimation:
                velocityEstimator.FinishEstimatingVelocity();
                velocity        = velocityEstimator.GetVelocityEstimate();
                angularVelocity = velocityEstimator.GetAngularVelocityEstimate();
                break;

            case ReleaseStyle.AdvancedEstimation:
                hand.GetEstimatedPeakVelocities(out velocity, out angularVelocity);
                break;

            case ReleaseStyle.GetFromHand:
                velocity        = hand.GetTrackedObjectVelocity(releaseVelocityTimeOffset);
                angularVelocity = hand.GetTrackedObjectAngularVelocity(releaseVelocityTimeOffset);
                break;

            default:
            case ReleaseStyle.NoChange:
                velocity        = rigidbody.velocity;
                angularVelocity = rigidbody.angularVelocity;
                break;
            }

            if (releaseVelocityStyle != ReleaseStyle.NoChange)
            {
                float scaleFactor = 1.0f;
                if (scaleReleaseVelocityThreshold > 0)
                {
                    scaleFactor = Mathf.Clamp01(scaleReleaseVelocityCurve.Evaluate(velocity.magnitude / scaleReleaseVelocityThreshold));
                }

                velocity *= scaleFactor * scaleReleaseVelocity;
            }
        }
Пример #7
0
        //-------------------------------------------------
        private void OnDetachedFromHand(Hand hand)
        {
            attached = false;

            // Modification of the OnDetachedFromHand method, disabling default behaviour of the throwable if
            // an attempt was made

            KeyObject.ObjectState state = keyObjectScript.TryGoal();
            keyObjectScript.currentHand = null;
            keyObjectScript.UnsetHeld();
            //Default behaviour
            onDetachFromHand.Invoke();

            hand.HoverUnlock(null);

            Rigidbody rb = GetComponent <Rigidbody>();

            rb.interpolation = RigidbodyInterpolation.Interpolate;

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

            // If the object is released on something different from a goal, we want it to adopt the valve default behaviour
            // This is done to avoid objects respawning with a given velocity (from the velocity estimator) when dropped on a bad goal
            if (state == KeyObject.ObjectState.NotOnGoal)
            {
                rb.isKinematic = false;
                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);
            }
            else if (state == KeyObject.ObjectState.OnBadGoal)
            {
            }
            else if (state == KeyObject.ObjectState.OnGoodGoal)
            {
            }
        }
Пример #8
0
    void Update()
    {
        if ((SteamVR_Actions._default.GrabPinch.GetState(RightInputSource) || SteamVR_Actions._default.GrabPinch.GetState(LeftInputSource)) && attachedController == null && !introScene)
        {
            // Trigger pulled when frisbee not on hand => Recall
            if (SteamVR_Actions._default.GrabPinch.GetState(RightInputSource))
            {
                attachedController = rightController;
                SoundManager.instance.PlayRecallRight();
            }
            else
            {
                attachedController = leftController;
                SoundManager.instance.PlayRecallLeft();
            }
            // Initialize the recall
            rigidbody.useGravity = false;
            recalling            = true;
            recordingPos         = false;
            //recallStartPosition = transform.position;
            recallStartTime = Time.time;
            // Clear velocity
            //rigidbody.velocity = Vector3.zero;
            // Also estimate the velocity
            velocityEstimator.BeginEstimatingVelocity();
            FrisbeeSphere.material = recallMaterial;
            foreach (MeshRenderer renderer in frisbeeRim)
            {
                renderer.material = rimRecallMat;
            }
        }
        else if (introScene)
        {
            // Frisbee drifts towards player
            transform.position = Vector3.MoveTowards(transform.position, GameManager.S.player.transform.position, 0.01f);
        }
        else if (recalling && (SteamVR_Actions._default.GrabPinch.GetState(RightInputSource) || SteamVR_Actions._default.GrabPinch.GetState(LeftInputSource)))
        {
            // Non-physical recall
            Vector3 recallVector = attachedController.position - transform.position;
            rigidbody.MovePosition(transform.position + Vector3.Normalize(recallVector) * Mathf.Min(recallSpeed * Time.deltaTime * (Time.time - recallStartTime), recallVector.magnitude));
            //rigidbody.MovePosition(Vector3.Lerp(recallStartPosition, attachedController.position, (Time.time - recallStartTime)/0.2f ));
            if (SteamVR_Actions._default.GrabPinch.GetState(RightInputSource))
            {
                vibration.Execute(0.0f, 0.1f, 40.0f, 0.1f, RightInputSource);
            }
            else if (SteamVR_Actions._default.GrabPinch.GetState(LeftInputSource))
            {
                vibration.Execute(0.0f, 0.1f, 40.0f, 0.1f, LeftInputSource);
            }
        }
        else if (recalling && !(SteamVR_Actions._default.GrabPinch.GetState(RightInputSource) || SteamVR_Actions._default.GrabPinch.GetState(LeftInputSource)))
        {
            // Recall cancelled (dropped)
            if (attachedController == rightController)
            {
                vibration.Execute(0.0f, 0.1f, 20.0f, 0.1f, RightInputSource);
            }
            else if (attachedController == leftController)
            {
                vibration.Execute(0.0f, 0.1f, 20.0f, 0.1f, LeftInputSource);
            }
            recalling            = false;
            rigidbody.useGravity = true;
            attachedController   = null;
            // Apply estimated velocity
            velocityEstimator.FinishEstimatingVelocity();
            rigidbody.velocity = velocityEstimator.GetVelocityEstimate();
            // Restore material
            FrisbeeSphere.material = originalMaterial;
            // foreach(MeshRenderer renderer in frisbeeRim){
            //     renderer.material = rimOriginalMat;
            // }
            for (int i = 0; i < frisbeeRim.Length; i++)
            {
                frisbeeRim[i].material = rimOriginalMats[i];
            }
        }
        else if (!recalling && recordingPos)
        {
            frisbeePositions.Add(transform.position);
        }

        if (!(SteamVR_Actions._default.GrabPinch.GetState(RightInputSource) && attachedController == rightController) &&
            !(SteamVR_Actions._default.GrabPinch.GetState(LeftInputSource) && attachedController == leftController) &&
            attachedController != null)
        {
            // Throwing the frisbee
            frisbeePositions = new List <Vector3>();
            frisbeePositions.Add(transform.position);
            recordingPos          = true;
            transform.parent      = null;
            attachedController    = null;
            rigidbody.useGravity  = true;
            rigidbody.isKinematic = false;
            // Apply velocity estimated by VelocityEstimator
            velocityEstimator.FinishEstimatingVelocity();
            // Curve the frisbee towards the center
            float degreesFromCenter = Vector3.Angle(velocityEstimator.GetVelocityEstimate(), mainCamera.rotation.eulerAngles);
            if (degreesFromCenter < 45.0f)
            {
                Vector3 adjustedDirection = (degreesFromCenter / 45.0f) * velocityEstimator.GetVelocityEstimate().normalized + ((45.0f - degreesFromCenter) / 45.0f) * mainCamera.forward;
                rigidbody.velocity = adjustedDirection * velocityEstimator.GetVelocityEstimate().magnitude * 1.5f;
            }
            else
            {
                rigidbody.velocity = velocityEstimator.GetVelocityEstimate() * 1.5f;
            }

            rigidbody.angularVelocity = ScaleLocalAngularVelocity(velocityEstimator.GetAngularVelocityEstimate(), new Vector3(0.1f, 1.0f, 0.1f));

            SoundManager.instance.PlayThrow();
            gravityField.SetActive(true);
        }

        // if(!firstItemSuccess /*&& Tutorial.IsTutorial()*/ && GameManager.S.GetDestroyedScore() > 0){
        //     SoundManager.instance.PlayItemSucceed();
        //     firstItemSuccess = true;
        // }
    }