Mount your webcam over the X-axis stepper motor so that it moves up with the Z-axis.
I have made about 10 versions of this, and this is my final one.
Works with CR touch.
The author marked this model as their own original creation.