Dont worry about where the gate is until the latter part of the leg, the most mportant thing is to beat the boats around you.
If you are with another boat, either attacking or defending, you need to gybe just BEFORE he does.
How you are supposed to know when the other guy is going to gybe is another story - mind reading?
Paul