We built a cannon to fire Nerf darts at the un-dead for Zombie Apocalypse:
The gun is mounted on a turntable; a render of the interior is shown below.

A servo is mounted in a 3-legged “caddy”. The legs of the caddy have Lego wheels which run on a track to support the turret, providing very smooth movement combined with a very stable gun mount. There is also a centre bearing (which is under the servo in this diagram). The servo drives a Lego gear which engages on a 3D printed rack. Since the diameter of the rack is about four times that of the gear, the mechanism divides the travel of the servo by about four. Hence the ±90° turn of the servo results in a ±23° turn of the turret.
A tilt mechanism, which is shown below, is mounted on top of the turntable. Here, two Lego gears are used, one attached to the servo drive shaft, the other to the gun’s side support. Again, a reduction ratio is used so that the ±90° turn of the servo results in a ±23° tilt of the gun.

Finally, the interior of the gun is shown below.

The motors, flywheels, and barrel liner (which is rifled!) are used from a Nerf gun. A Lego pinion is attached to a servo; it engages in a 3D printed rack so that it can push a Nerf dart between the flywheels, hence firing the gun.
As it stands, this design would have a problem. Vibrations from the motors cause the Nerf darts to creep forward into the path of the flywheels. Hence, the gun will fire darts even if the trigger servo has not moved. To counter this, the lid of the gun has a hole into which a tuft of bristles from a toothbrush have been glued. This provides enough resistance to stop the darts wandering into the flywheels due to vibration, but not so much that the gun can’t fire.
The gun can be seen mounted on a box on the back of Firefly. The box contains a Raspberry Pi which interfaces to an under-barrel mounted camera (which isn’t shown on the images). We used a bright red torch to put a red circle of light on the Zombies. Code in the Pi adjusted the servos in the turret until a specified pixel was aligned with the centre of the bright spot. At this point, the gun fires.