It doesn't prevent lock - Vader gets lock on Luke twice, though it takes longer to get lock, and he takes a LOT of time before he can even start to attempt lock each time. Even with lock, he fails to hit anything but R2D2.
It's clearly implied that this is caused by the Force, and I know of no alternative theory.
The time data clearly shows that there is a vast difference in attempting to shoot down Luke, compared to the other Rebel pilots in the same situation. I timed the engagement times of all of the attacks by Vader and his wingmen on fighters in the trench. They don't always depict the use of a targeting computer, but we do always hear the firing times and see the results, which indicate that Luke, right after Obi-Wan tells him to use the Force and Vader acknowledges it, is the only one to avoid destruction, and he survives far longer than all of the rest combined. The numbers seem very convincing to me:
(All times approximate but seem accurate within one second.)
Y-Wing 1 - Vader takes 3 seconds to lock, fires for 3 seconds, destroyed.
Y-Wing 2 - Vader fires for 1 second, destroyed.
Gold Leader - breaks away. Vader fires for 1 second, destroyed.
Red Leader's group:
X-Wing 1 - Vader takes 2 seconds to lock, fires for 2 seconds, destroyed.
X-Wing 2 - Wingman fires for 1 second, destroyed.
Red Leader - outside trench, Vader fires once for vital damage, then finishes him in a second burst. Total time firing 6 seconds. Total attack time outside the trench, about 15 seconds.
Wedge - Wingman fires for 3 seconds, Wedge is out of action but escapes.
X-Wing - Vader fires for 2 seconds, destroyed.
Luke - Vader spends a total of about 10 seconds locking on and fires for about 5 seconds total, hitting only R2D2. Vader takes a total of 60 seconds from when he's on Luke's tail and says "The Force is strong with this one!" till his final shot, including a 23-second delay between when he hits R2, and when he's able to start locking in the second time (which takes about 7 seconds, more than twice as long as any other lock-on attempt). Vader also wastes a second after getting the second lock to say, "I've got you now!" before he fires, and then fires for about two seconds but all his shots miss, and then Han hits one of his wingmen and he stops firing. (So maybe that last remark prevented him killing Luke, but as we see in later films, the Force seems to have a perfect sense of timing, allowing parrying and intentionally aimed deflection of blaster bolts, so I'd say this timing is not coincidence, whether we attribute it to the Force or to Lucas.)
So, Luke required at least between 10 to 60 times as much time for Vader to take out, compared to everyone else in the same situation, and we don't even know Vader would've hit even then - he fired maybe 7 blasts on the last 2-second attack before there was anything to interrupt him, and missed. Luke and Wedge were the only ones to survive being shot at in the trench, and Luke only got hit in the droid.
The sequence of events clearly implied to me even when I saw this the first time when I was a kid, that this was all about using the Force:
11:54 "Use the Force, Luke"
12:04 "The Force is strong with this one!"
12:26 Vader aims
12:29 Vader fires
12:31 R2 hit: Vader stops firing
12:54 Vader starts locking in
13:01 Vader gets lock
13:02 "I have you now!"
13:03 Vader fires
13:04 Han hits wingman: Vader stops firing
13:05 Vader says "What?"
13:07 Han says "Ya-hoo!"
13:09 wingman says "Look out"
13:20 Luke fires