That's what a gimbal does, or a laser level. I haven't seen laser levels that small however. Do you want it to stay fixed on the surface? Is it a static surface? Flat or not? Or do you just want smooth motion, because if so a small gimbal holding a laser is the easiest solution. Everything else gets difficult fast
Edit: I think you want to look at gimbals for drones if you want something small. Some of these will even have stand-alone object tracking. But then you need to arrange for something to connect it to, supply power, etc. All the good normal gimbals are for handheld phones or cameras and are not easily pocketable. The pocketable "normal" gimbals sacrifice something that makes them unusable here.
