Dumb luck. I was at periapsis on my first flyby, and noticed that the Gas Planet -might- be in the right position for a flyby, so I tried to do so, and got a fairly close pass, then, just a bit before the second encounter, changed my trajectory slightly to bring it in as close as possible without slamming into the atmosphere. You barely need any fuel for trajectory corrections, once you've gotten the brunt of the delta-v out of the way with your main rocket.