Ejemplo n.º 1
0
        /// <summary>
        /// Turns the barrel of the tank at the player
        /// </summary>
        private void TurnToPlayer()
        {
            if (player)                                                                       // player is the target
            {
                Vector3 disToTarget = player.position - transform.position;                   // how far away is the player

                Quaternion targetRotation = Quaternion.LookRotation(disToTarget, Vector3.up); // how the player is rotated
                Vector3    euler1         = transform.localEulerAngles;                       // get local angles
                Quaternion prevRot        = transform.rotation;
                transform.rotation = targetRotation;                                          // Set Rotation
                Vector3 euler2 = transform.localEulerAngles;                                  // get local angles again

                if (lockRotationX)
                {
                    euler2.x = euler1.x;                //revert to  previous value;
                }
                if (lockRotationY)
                {
                    euler2.y = euler1.y;                //revert to previous value;
                }
                if (lockRotationZ)
                {
                    euler2.z = euler1.z;                                                                          //revert to previous value;
                }
                transform.rotation = prevRot;                                                                     // go back to previous Rotaion

                transform.localRotation = AnimMath.Slide(transform.localRotation, Quaternion.Euler(euler2), .5f); // slides into a smoother rotation
            }
            else
            {
                transform.localRotation = AnimMath.Slide(transform.localRotation, startingRotation, .05f);
            }
        }
Ejemplo n.º 2
0
        public static Quaternion Slide(Quaternion current, Quaternion target, float percentLeftAfter1Second = .05f)
        {
            float p = 1 - Mathf.Pow(percentLeftAfter1Second, Time.deltaTime);

            return(AnimMath.Lerp(current, target, p));
        }
Ejemplo n.º 3
0
        public static Vector3 Slide(Vector3 current, Vector3 target, float percentLeftAfter1Second)
        {
            float p = 1 - Mathf.Pow(percentLeftAfter1Second, Time.deltaTime);

            return(AnimMath.Lerp(current, target, p));
        }