Ejemplo n.º 1
0
        public virtual void PullTowards(NVRAttachJoint joint)
        {
            Item.SetFrozen(false);
#if NVR_Daydream || NVR_Gear
            Rigidbody.isKinematic = true;
            Vector3 pointOffset = this.transform.position - joint.transform.position;
            Item.transform.position = Item.transform.position - pointOffset;
            if (joint.MatchRotation == true)
            {
                Item.transform.rotation = joint.transform.rotation;
            }
#else
            //Preventing objects being pulled while hands are interacting
            if (true == Item.IsAttached)
            {
                return;
            }

            float velocityMagic        = VelocityMagic / (Time.deltaTime / NVRPlayer.NewtonVRExpectedDeltaTime);
            float angularVelocityMagic = AngularVelocityMagic / (Time.deltaTime / NVRPlayer.NewtonVRExpectedDeltaTime);

            Vector3 positionDelta  = joint.transform.position - this.transform.position;
            Vector3 velocityTarget = (positionDelta * velocityMagic) * Time.deltaTime;

            if (float.IsNaN(velocityTarget.x) == false && Item.Rigidbody)
            {
                velocityTarget = Vector3.MoveTowards(Item.Rigidbody.velocity, velocityTarget, MaxVelocityChange);
                Item.AddExternalVelocity(velocityTarget);
            }


            if (joint.MatchRotation == true)
            {
                Quaternion rotationDelta = joint.transform.rotation * Quaternion.Inverse(Item.transform.rotation);

                float   angle;
                Vector3 axis;

                rotationDelta.ToAngleAxis(out angle, out axis);

                if (angle > 180)
                {
                    angle -= 360;
                }

                if (angle != 0)
                {
                    Vector3 angularTarget = angle * axis;
                    if (float.IsNaN(angularTarget.x) == false)
                    {
                        angularTarget = (angularTarget * angularVelocityMagic) * Time.deltaTime;
                        angularTarget = Vector3.MoveTowards(Item.Rigidbody.angularVelocity, angularTarget, MaxAngularVelocityChange);
                        Item.AddExternalAngularVelocity(angularTarget);
                    }
                }
            }
#endif
        }
Ejemplo n.º 2
0
        public virtual void PullTowards(NVRAttachJoint joint)
        {
            float velocityMagic        = VelocityMagic / (Time.deltaTime / NVRPlayer.NewtonVRExpectedDeltaTime);
            float angularVelocityMagic = AngularVelocityMagic / (Time.deltaTime / NVRPlayer.NewtonVRExpectedDeltaTime);

            Vector3 positionDelta  = joint.transform.position - this.transform.position;
            Vector3 velocityTarget = (positionDelta * velocityMagic) * Time.deltaTime;

            if (float.IsNaN(velocityTarget.x) == false)
            {
                velocityTarget = Vector3.MoveTowards(Item.Rigidbody.velocity, velocityTarget, MaxVelocityChange);
                Item.AddExternalVelocity(velocityTarget);
            }


            if (joint.MatchRotation == true)
            {
                Quaternion rotationDelta = joint.transform.rotation * Quaternion.Inverse(Item.transform.rotation);

                float   angle;
                Vector3 axis;

                rotationDelta.ToAngleAxis(out angle, out axis);

                if (angle > 180)
                {
                    angle -= 360;
                }

                if (angle != 0)
                {
                    Vector3 angularTarget = angle * axis;
                    if (float.IsNaN(angularTarget.x) == false)
                    {
                        angularTarget = (angularTarget * angularVelocityMagic) * Time.deltaTime;
                        angularTarget = Vector3.MoveTowards(Item.Rigidbody.angularVelocity, angularTarget, MaxAngularVelocityChange);
                        Item.AddExternalAngularVelocity(angularTarget);
                    }
                }
            }
        }