If your distances can indeed only take one of two values, then it does not make a difference. In either case, your model will estimate one parameter for distance.
If you include distance as a continuous covariate, your parameter estimate can be interpreted as "the difference in the dependent variable (DV) associated with a 1cm change in distance". The intercept will encode the DV value at a distance of 0cm (and interpreting it won't make sense), and you can get the fit at 2 and 4cm by multiplying the parameter estimate by 2 and 4 and adding the result to the intercept parameter. You can in principle interpolate and extrapolate beyond the 2 and 4cm you had in your training data, but I would be very careful about this.
If you include distance as a categorical covariate, your software will choose one level as the reference level - typically the 2cm level, because it comes before 4cm in the alphabet. The intercept will now have an interpretation as "the fitted value of the DV at a distance of 2cm", and the parameter estimate for distance will give you the offset between the DV at 2cm and at 4cm distance. In this case, your model will not allow you to extrapolate beyond the 2 or 4cm you fed into the model.
(If you are using a generalized model, the interpretations above of course pertain to the predictor, not the response, where the interpretations depend on the link function.)
Thus, the parameter estimates of both the intercept and distance will differ between the two encodings of distance. All other statistics - the t value, the F statistic in an AN(C)OVA, the degrees of freedom, and the p statistics - should be unchanged between the two possible encodings. (Unless something strange happens. If so, tell us.) Try it!