What you’re looking for is what’s called a “Break Beam Sensor”. Break beam sensors come in a couple configurations, either one sided or two sided. Two sided beam sensors need power at both sides of the sensor setup, one sided use a reflector at one side with the light source and sensor combined at the other side.
I’ve been using this beam sensor in combination with this Z-Wave dry contact module for a couple of years now. The setup is super reliable and fast to respond. The one-sided configuration prevents me from having to run wire all over the place but takes careful alignment during setup. We have a lot of pets in the house and normal PIR motion sensors are constantly being tripped by cats and dogs. With the beam sensor I can set a beam at chest level which will only be triggered by humans.
The only downside is that the sensor has a physical relay so it clicks every time it’s triggered which might be annoying in some use cases.