I decided to make the Panzer VIII "Maus" tank in Blender as a way to experiment with techniques and such on the go, but i had also made another tank before the Maus and since then, i have still not been able to figure out how i can make the tank's turret and gun to be rigged properly. What i want is for the turret to be able to be rotatable on the Z axys (left and right), but the gun to follow the turret's rotation, WHILE the gun itself can rotate on the Y axys (up and down). Before, n my previous tank, i was able to make the Turret rotatable, but the gun was either left floating in the air, or not being able to rotate, WHILE remaining attached to the Turret. Here's a pic for a better understanding: Feel free to point out any mistakes with bone placement, that would also help me as i'm not yet familiar with rigging. I hope my explanation wasn't confusing or anything. Thanks in advance for any help!
Each bone has a head and a tail. The head is the centre point of any rotation, so you position the head at the centre point of the pieces rotation, for the turret that is the centre of its connection to the base and for the gun it is the end that is connected to the turret. Position each bone so that its movements make sense for the piece of the tank that it will control.
Now parent each bone to the piece that it is connected to, the turret is the parent of the gun and the base is the parent of the turret. When parenting bones you can choose between connected and keeping offset, choosing connected will move the head to the tail of the parent but keep offset will parent the bone without moving it, this allows the bone to follow the parent and keep its position for its rotations.
To make animating easier you can add some constraints.
For the turret and gun, under transform locks in the bone properties, enable the location locks, this prevents you manually moving the bones in pose mode.
For the turret add a Limit Rotation constraint and enable Limit X and Limit Y and change World space to Local Space, now it can only be rotated on its Z axis. Any time you press G or R it will only rotate the one direction you want it to rotate.
For the gun also add a Limit Rotation constraint. Enable all three limits and change to local space. Now set a min and max value for the X axis, in my quick example I found a max of 32 and a min of -4.2 looks about right, allowing you to rotate the gun up and down without hitting the tank body and not point straight up in the air.
Here is my simple example rig.