If the stormtroopers are such bad shots, then how were they able to nearly stamp out the rebel forces before Luke showed up? They demolished Hoth, nearly won on Endor and everybody but Leia on the Blockade runner, for instance. Yet we only focus on how they couldn't hit characters with plot armor who took them by surprise. Seriously, how many times do you think people break into a Death Star?

They deliberately missed.
They were ORDERED to miss.
Because a tracking device was on the Falcon to find the rebel base.
In fact, the fact that they missed every time was a credit to their marksmanship.

The thing people don't quite seem to grasp, probably because they never graduated third grade, is that the Stormtroopers were TOLD TO MISS. The fact that despite firing hundreds of thousands of shots at the main cast, they missed everyone, proves that thy were incredibly accurate.