How can I get homemade yoghurt to thicken properly?
There are many myths surrounding yogurt making:

UHT milk is bad. This is simply not true. I have made yogurt with whole fat UHT milk for years and it comes out nice and thick. In fact for the past several months I have been using a high quality whole milk powder that makes a lovely, thick yogurt.
Store bought yogurt will always be thicker because of additives. Also not true. My yogurt is as thick as a high fat sour cream and contains no added milk powder, gelatine, etc.
You need many hours of 'fermentation' to make yogurt. Again I don't agree. My yogurt sets in 3-4 hours, after which it goes in the fridge to cool and finish the culturing process.
The milk must be exactly x temperature when you add the starter. This is only somewhat true. As long as the milk is at or below 45°C it is fine. If you can stand the temperature, so can the bacteria—ie, if you can hold a finger in it for ~10 sec, it's ok. That said, too low and you're losing some effects of the protein denature explained below.
Everything must be sterilized. This is only somewhat true. Clean everything carefully, of course, but you are adding a starter with billions of cultivated bacteria into an ideal environment for it to grow. It will easily dominate other bacteria that happen to get in—and they will, since there are bacteria in the air all around us, so even post-sterilization there will be plenty of foreign stuff entering the yogurt. That said, an over-long incubation will give other bacteria a chance to express themselves, so best to avoid that.
Don't move, touch, or cause the yogurt to shake in any way during incubation or it will fail. I used to believe this myself but it's really not that sensitive. Obviously less agitation is better, but it will not fail even with fairly substantial movement during the incubation. Drinking yogurt is shaken quite violently during incubation in order to keep it liquid and even then it's still quite viscous.

The keys to making good thick yogurt are:

Protein. The milk becomes solid because of a protein in the milk, and for that to happen, the protein must first be heated to above 70°C. I heat it to 75-80°C for just a few minutes and it still turns out very thick. A milk with high quality protein will make a great yogurt.
Incubation temperature. If you want to make good yogurt in 3-4 hours (beyond which it will not get thicker, only more sour), it must be incubated at a steady 40-45°C. A lower temperature will also produce yogurt, but you are in a race with other bacteria, so the quicker it's done the better. Buy a 75-cent indoor thermometer and start looking for ways to create the right temperature environment.
Time between generations. Try to bake a new batch every 4-5 days. After a week in the fridge the bacteria are starting to suffer and will not be as strong and active when introduced into the next batch. A short generation cycle will let you go on making yogurt with the same culture for dozens of generations.
Sugar quantity. This is my own personal guess based on bread making, etc. A little sugar will boost the bacteria, but too much will slow it down. I use 2 tbsp per litre of milk and it works very well. Tart with a hint of sweet. Up to double this amount should be fine but more could affect it. Like I say I'm guessing here but it seems to make sense.

Two final notes.

The &quot;water&quot; that separates out of the yogurt is whey protein—generally seen as a very healthy thing to eat. A firm yogurt will let you pour it or spoon it off if you don't like it, but there's no reason not to just scoop it out with the rest or stir it back in.
Fat content is important, but the milk protein is what will make or break the yogurt. I have made a very thick yogurt with skim milk powder or skim milk with added skim milk powder. Soy milk, which has quite a bit less fat than whole milk, makes a very solid yogurt. It's all about solids. Of course a &gt;3.x% whole fat milk will produce a tastier yogurt, because milk fat is oh so tasty!

Further reading from an industry source:
http://www.dairyconsultant.co.uk/si-yoghurt.php
Additional tips:
http://www.facebook.com/diyhelpers