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;
        }
Exemple #2
0
        public virtual void Detached(NVRAttachJoint joint)
        {
            Rigidbody = Item.Rigidbody;

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

            if (Item.EnableGravityOnDetach == true)
            {
                Rigidbody.useGravity = true;
            }
        }
        public virtual void Detached(NVRAttachJoint joint)
        {
#if !UNITY_ANDROID
            Rigidbody.useGravity = true;
#endif
            IsAttached = false;

            AttachedJoint = null;
        }
        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;
        }
        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;
        }
Exemple #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;
        }
Exemple #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);
                    }
                }
            }
        }
Exemple #10
0
 public virtual void Detached(NVRAttachJoint joint)
 {
     IsAttached = false;
     Rigidbody.useGravity = true;
 }