How did old autopilots work? With fly-by-wire and computers between pilot's command and flight control surfaces, it is easy to imagine the implementation of an autopilot inside the computer, but I read somewhere that autopilots existed before WW2. They were made only to maintain altitude and heading, but worked at a that time with the mechanical linked between pilot and control surfaces.

How did these old autopilots work?
It used a set of gyroscopes and pendulums that would correct the plane's attitude when it deviates. They were usually enhanced with pneumatic or hydraulic power to actually move the control surfaces.

For example the V-1 flying bomb (WW2 German UAV) could fly across the Channel and initiate a dive after a preset distance. It remained on course using a pendulum for pitch control and a gyroscope for yaw control. It used its inherent stability for roll control (no ailerons).