Preserving depth when rendering in multipe layers (Cycles) I don't even know how to ask this question  and I a noob to blender.

I wanted to create a plasma canon 

I created 3 render layers and Added them on top of each other...

For now this looks pretty good

Gun Front


Compositing tree


But then I tried to look at the gun from the back.... the bullet gets put in top of the gun. Is there any (easy) way to have the layers retain Z order?

Gun view back (bad)
Yeah no problem,

On the flame render layers layer settings, under the Layer: blocks, there's a Mask Layer:   set of blocks.   Just select the corresponding layer for the cannon (so you're applying the cannon as a mask to the flame)



Below is an example using a cube and a sphere, the sphere occluding and masking the cube.



The Cubes' render layer output