public static double MoveTowards(double current, double target, double maxDelta) { if (MathD.Abs(target - current) <= maxDelta) { return(target); } else { return(current + MathD.Sign(target - current) * maxDelta); } }