Think about it. In ANH they blast through Tantive IV dropping rebel troops left and right. They try to stop the Falcon from taking off so are blasting at it with heavy artilary and not at Han. On the Death Star they are sucker punched when they go to investigate the Falcon. The imperial officers in the control room are taken by surprise more than missing shots, same as the officers in the detention block. The stormtroopers stand off in same detention block is fired in a thin hall to the left of them with lots of smoke all over and the heroes taking shelter on the protruding sides of the hallway and all four are shooting wildly out of the corridor constantly, making it difficult for the troops to take a shot without being shot. The troopers are again taken by surprise and spooked by Han when he goes crazy and gives chase. Then he backs out of that garrison before they have time to retaliate again using the winding corridors of the Death Star for cover. Luke and Leia too use the twisting corridors and fleeing speed to evade the troopers before they could get a clean shot. The stormtroopers blasts would have hit Luke right in the face had Leia not closed the blast door. Next, Luke and Leia take cover on the alcoves of the doorway to shoot the troopers above them and swing across quickly. The troopers that fire at the heroes as they board the Falcon are very far away and the Falcons boarding ramp deflects many of the blasts. In review it seems like the stormtroopers on the Death Star are just not trained for, or prepared to fight guirella insurgents. They are trained for overwhelming battlefield combat it seems. The heroes are just more sneaky and have the element of surprise. The stormtroopers also feel too powerful and secure aboard the mighty Death Star to expect such attacks so close to home. The older more experienced stormtrooper used to nothing going wrong advises his younger counterpart to relax. "That's nothing. Outgassing, don't worry about it" a classic case where experience in a rapidly changing world is more of a liability than an advantage!