So I've spent the last 3 days trying to setup my Raspberry Pi Camera as a webcam for my windows computer. I recently did the setup using a streaming script with python, it works but the latency was way higher than I expected. So I looked for ways to set ip up through USB connection (or OTG -> on the go connection). Raspberries (at least pi02w and some other newer models) have OTG support, to begin with, you should look if your model has support for it, otherwise it might not be worth going through this anyway. 

But ok, to do the setup I, logically, went to an official documentation from Raspberry. Why not? OF COURSE it would work ok, but no it didn't.  Besides my problems, I've also seen there are some other problems of this tutorial not working for models like the 3B

Ok but anyway, lets consider you have a pi zero 2 w, which was my case. You can follow most of the official tutorial I linked to, but there are some important tips and common problems I went to a couple of times. 

OS Version

As they say on the tutorial, it was made for Bullseye and not Bookworm (the current latest OS for the Pi), so when you are installing the os on the MicroSD using the imager, go with Bullseye and use the Lite version (you wont need a desktop setup for this anyway, but it should work as well).  And don't forget to do the basic Wifi and SSH setup while you are flashing the SD card, otherwise you are going to have problems. 

Update

I would advice against doing apt update and full upgrade, just to make sure you are kept and the version you want to, and not the latest. 

Config file 

There is a problem here at the tutorial, they say /boot/firmware/config.txt but from what I've read, this is something that changed on the Bookworm, so you are probably going to have /boot/config.txt, without the firmware folder, as it's the older setup. 

And they tell you to do the setup this way:

$ echo "dtoverlay=dwc2,dr_mode=otg" | sudo tee -a /boot/firmware/config.txt

I recommendo going inside the file with sudo nano /boot/config.txt and editing the lines yourself. 

At the TOP of the file, above everything, add these lines:

dtoverlay=dwc2
dr_mode=otg
camera_auto_detect=1
gpu_mem=128
camera_auto_detect=1

If you see any of these lines at any other part of this file, comment it, you only need it once, and here at the top. The [all] can be kept empty.

UVC Install

Do as was said at the tutorial, no problems here. You may have a memory problem during the installation (step 13/18 to be more precise) as I had, so just try again. 

For the rest also just do as they say, no need to change nothing. I would only recommend doing this different line at rc.local so you can see the logs of the startup:

/home/<username>/.rpi-uvc-gadget.sh > /home/<username>/rpi-uvc-gadget.log 2>&1 &

It is a good idea to first try to run the script manually before rebooting your Pi and letting it run automatically on boot, because you can detect errors this way. 

Windows Driver

This was the worst part for me, by far. I though there couldn't be anything wrong with my windows PC where I was trying to use the webcam, so I didn't even look into it until I had tried everything else. I was using a tool to check my USB cable connection status, because I thought it was some problem withe the cable itself not being able to transfer data, but it wasn't so. 

It was showing up as "USB Ethernet RNDIS" instead of something about UVC. Apparently this is the standard driver chosen by windows for the USB connection with Raspberry, it didn't detect automatically that I wanted to use as an OTG device. In order to solve that you need to chose the right driver by going to:

Device Manager > Right-click on "USB Ethernet/RNDIS Gadget" > Select "Update Driver" > Choose "Browse my computer for drivers" > Select "Let me pick from a list" > USB Composite Device

When you do it, if everything else is working ok, the PI camera should finally appear as an UVC camera:

Conclusion

I've gone through the main errors I got during the installation, hope it have helped you solving yours as well. Besides everything I said, dont discard the basics like bad camera cable connection on Pi port and bad USB cable.