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); } }