Пример #1
0
        public virtual void Attached(NVRAttachJoint joint)
        {
#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
            Vector3 targetPosition = joint.transform.position + (Item.transform.position - this.transform.position);
            Rigidbody.MovePosition(targetPosition);
            if (joint.MatchRotation == true)
            {
                Rigidbody.MoveRotation(joint.transform.rotation);
            }

            Rigidbody.velocity        = Vector3.zero;
            Rigidbody.angularVelocity = Vector3.zero;
#endif
            IsAttached           = true;
            Rigidbody.useGravity = false;

            AttachedJoint = joint;
        }
Пример #2
0
        public virtual void Detached(NVRAttachJoint joint)
        {
            Rigidbody = Item.Rigidbody;

            IsAttached           = false;
            Rigidbody.useGravity = true;
        }
Пример #3
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
        }
Пример #4
0
        public virtual void Detached(NVRAttachJoint joint)
        {
            IsAttached = false;

            if (Item.EnableGravityOnDetach == true)
            {
                Rigidbody.useGravity = true;
            }
        }
Пример #5
0
        public virtual void Detached(NVRAttachJoint joint)
        {
#if !UNITY_ANDROID
            Rigidbody.useGravity = true;
#endif
            IsAttached = false;

            AttachedJoint = null;
        }
Пример #6
0
        public virtual void Attached(NVRAttachJoint joint)
        {
            Vector3 TargetPosition = joint.transform.position + (Item.transform.position - this.transform.position);
            Rigidbody.MovePosition(TargetPosition);

            Rigidbody.velocity = Vector3.zero;
            Rigidbody.angularVelocity = Vector3.zero;

            IsAttached = true;
            Rigidbody.useGravity = false;
        }
Пример #7
0
        public virtual void Attached(NVRAttachJoint joint)
        {
            Vector3 TargetPosition = joint.transform.position + (Item.transform.position - this.transform.position);

            Rigidbody.MovePosition(TargetPosition);

            Rigidbody.velocity        = Vector3.zero;
            Rigidbody.angularVelocity = Vector3.zero;

            IsAttached           = true;
            Rigidbody.useGravity = false;
        }
Пример #8
0
        public virtual void Attached(NVRAttachJoint joint)
        {
            Vector3 targetPosition = joint.transform.position + (Item.transform.position - this.transform.position);

            Rigidbody.MovePosition(targetPosition);
            if (joint.MatchRotation == true)
            {
                Rigidbody.MoveRotation(joint.transform.rotation);
            }

            Rigidbody.velocity        = Vector3.zero;
            Rigidbody.angularVelocity = Vector3.zero;

            IsAttached           = true;
            Rigidbody.useGravity = false;
        }
Пример #9
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);
                    }
                }
            }
        }
Пример #10
0
 public virtual void Detached(NVRAttachJoint joint)
 {
     IsAttached = false;
     Rigidbody.useGravity = true;
 }