There's no secret, you just have to understand what you are trying to do, be very careful, and have some luck. The main thing to remember is that fishing the pilings takes a lot of attention, you cannot simply sit your rod down and leave it to the current and walk away. I always am holding my rod when I am fishing around pilings and usually, depending upon the pier, am often guiding the line with my hand. If you feel the hook tangling in a piece of kelp or snagging on a mussel you must immediately try to work it free. Sometime it works, sometimes it doesn't.
The direction and strength of the current is of course important. When water is slack and there is no current it's easy to fish straight down and avoid tangles. The opposite is when the current is very heavy and water is crashing against the pilings. It can be almost impossible to fish the piling area in such conditions without some loss of hooks/sinkers. Unfortunately, slack water conditions with no current usually also means fewer fish since most species like some water movement with 2-4 foot of movement ideal for perch.
Most of the time there is a moderate current coming in and going out from the piling. You drop your rig on the side of the piling where water is pushing toward the piling so that it is near the mussels and other attractants. But, as said, you must watch and feel your line at all time. You can set up on the side of the piling where water is pushing it away, and have less danger of it going into the piling, but then for most of the time your line is being pushed away from the very place you are trying to fish.
The actual area I am fishing, the water depth, depends somewhat on where I am fishing and and species I am targeting. When fishing the central and northern piers I will generally start at the bottom to see if I get any bites. Gradually I will move the line up in 1-2 foot increments until I find some fish. The bottom may yield some rockfish or cabezon while various species of perch inhabit different water depths. If targeting the big pileperch you can usually just fish the upper water levels since that is usually where they are found. Down south I will often start at the bottom seeing if there are any bass, sculpin (scorpionfish) or even cabezon but most of the action will probably be mid-depth for various perch species.
Fishing the pilings seems easy but if you want to be successful, and you want to avoid losing a lot of rigs, you must be careful and learn the "feel" of what is going on. But, even then you will lose some tackle.