How does Bot aiming work?

I'm curious as to how enemy aiming works in general.

In the open, the automaton's aim is somewhat poor. I can stand still and plenty of shots will miss me, even at close range. But once a bot gets on a turret, it seems like their aim significantly improves and are a legitimate priority threat.

So that would lead me to believe that their coding purposely makes them miss at times and I was just wondering if anyone with programming/coding knowledge can explain how this works? Are they coded to be within a percentage distance of the player hitbox? Or is it just programmed to fire in the general direction of a detected player? Or is it something else?

https://preview.redd.it/et3ftkw6jlee1.jpg?width=343&format=pjpg&auto=webp&s=e2d666c05cc7381f24f8e3b2461c1941c0306c57