Esempio n. 1
0
        /// <summary>
        /// This is essentially the same as Lerp but instead the function will ensure that the speed never exceeds maxDistanceDelta.
        /// Negative values of maxDistanceDelta pushes the vector away from target.
        /// </summary>
        public static PointF MoveTowards(this PointF current, PointF target, float maxDistanceDelta)
        {
            var dir       = target.Sub(current);
            var magnitude = dir.Length();

            if (magnitude <= maxDistanceDelta || magnitude <= float.Epsilon)
            {
                return(target);
            }
            return(current.Add(dir.Mul(maxDistanceDelta / magnitude)));
        }