The misses serve the scene

Stormtroopers are trained soldiers, but the films often use their blaster fire less as a test of marksmanship than as a way to keep heroes moving. A volley that hits a wall beside a fleeing character creates danger without ending the story. If the heroes are meant to escape, the shots have to miss—and repeated near misses become a visual joke.

That pattern is selective, not universal. In A New Hope, stormtroopers overwhelm the defenders aboard Princess Leia’s ship. Their apparent ineptitude is most noticeable when they are shooting at central characters, who need to survive for the plot to continue.

Sometimes the escape is the plan

The first film also gives one chase a tactical explanation. After the heroes escape the Death Star, Princess Leia realizes the Empire may have let them go so it can follow them to the Rebel base. The missed shots in that sequence are therefore not necessarily evidence that the soldiers cannot aim: the Empire’s larger goal matters more than stopping the fugitives immediately.

That explanation does not account for every comic near miss across the films. The broader reason is storytelling: stormtroopers supply a steady, intimidating stream of fire while the protagonists dodge, improvise, and survive. Their aim is a running gag because the heroes’ survival is the scene’s real objective.