Imperial Stormtrooper Marksmanship Academy/Analysis

So why were the Stormtroopers in Star Wars such bad shots?
First of all, the Stormtroopers' reputation for being bad shots is a bit exaggerated. They do quite well against the Rebels at the beginning of A New Hope and in the Hoth battle in The Empire Strikes Back. For example, they can hit rebel soldiers from at least ten meters away simply by hip-firing. It's mainly in the presence of Plot Armor-wearing main characters that their aim starts to degrade. And in A New Hope, the Stormtroopers were under orders from Tarkin to let Luke and his pals escape so that they could be tracked to the Rebel base—so the troopers (or at least the most fanatical ones) were trying to miss. And in the one scene where the troopers were trying to take prisoners, they were able to hit Princess Leia with a stun gun on their very first shot. However, that still does leave some unexplained scenes where the Stormtroopers were far worse shots than the protagonists.

According to some Expanded Universe sources, the standard-issue Imperial rifles were, and the Imperial administration was too cheap and lazy to fix this known defect. (Which doesn't explain why Han, Luke, and Leia were able to shoot quite accurately with Stormtrooper rifles in the Death Star and Cloud City...) Fanon also speculates that Stormtroopers' helmets restrict their vision (recall Luke's "I can't see a thing in this helmet!") or have shoddy targeting.

On the other hand, Cracked.com offers an interesting psychological explanation, pointing out that the Stormtroopers' on-screen accuracy is consistent with Real Life studies demonstrating that people (even trained soldiers) have inhibitions against firing at individuals with visible faces (like Luke and his pals), but fewer inhibitions against firing at others who can be dehumanized (like faceless Jawas or uniformed Rebel soldiers). The Stormtroopers' own face-concealing armor didn't do them any favors in this equation.(Then again they didn't have a problem burning two unarmed civilains to death)

As for the Clone Troopers' superiority over the Stormtroopers, the Clones almost certainly didn't have to suffer from hardware as shoddy as their successors did. (Recall that Clone Troopers in the swamps of Kashyyyk got to wear camouflage armor, then 20 years later Stormtroopers in the forests of Endor had to wear the standard, blindingly white armor.) It also helped that the Clone Troopers were cloned from known Badass Jango Fett, while the Stormtrooper ranks were diluted with soldiers from far-less-badass sources, like recruits and non-Jango clones.

And the battle droids? The canon explanation for their shoddy aim is that they really are that bad. The Trade Federation's battle strategy emphasized quantity over quality, seeking to overwhelm the opponent with huge numbers of disposable troops. The standard B1 Battle Droids were so disposable that, after Episode I, they were relegated to comic relief, rather than presented as a threat. Upgraded versions, like the Droidekas and Super Battle Droids, do pose a threat in later episodes, but even so, they tended to only succeed against Jedi in situations where the Inverse Ninja Law was working against the Jedi.

Now, for the really baffling part: When Stormtroopers or battle droids fire at a main character with a blaster, they tend to miss entirely. When Stormtroopers or battledroids fire at a main character who is a lightsaber-wielding Jedi, their shots are on-target or darn close—enabling the Jedi to deflect the shots (usually right back at their attacker) with said lightsaber. It is at this point that Watsonian analysis must either invoke the Force, or wash its hands of the matter and walk away.