Exemplo n.º 1
0
        /// <summary>Similar to StepTo method but for Angles.</summary>
        public static float RotateTowards(float angle, float target, float amount)
        {
            if (angle == target)
            {
                return(angle);
            }

            // Counter-Clockwise?
            if (!Utils.RotateClockwise(angle, target))
            {
                amount = -amount;
            }

            // Add (without going past 180 or -180)
            if (angle + amount > 180)
            {
                angle = angle + amount - 360;
            }
            else if (angle + amount < -180)
            {
                angle = angle + amount + 360;
            }
            else
            {
                angle += amount;
            }


            if (angle > target - amount && angle < target + amount)
            {
                angle = target;
            }

            return(angle);
        }