It just takes practice. I have days when i can cast real nice loops and get somewhat good distance. other days my line falls in a pile on the water and i cant get any farther than 10yds. (I have more bad days than good lately) I dont practice like I should, and when the bad days happen i get frustrated and it usually gets worse. So then i usually set the rod down and just set on a log, grab the copenhagen, and just watch the water, or take some pictures, or just enjoy the scenery. In short, I relax. After a bit i take the rod and make some short, good casts and then just let it happen from there. usually it gets better.
Keep your line clean, practice, take a class if you can, or go out for a day with a guide that caters to beginners if that is in your budget. As Ard mentioned, study the mechanics of the fly cast.