Monster behavior

Monsters in the Doom engine games have a primitive artificial intelligence that follows a set of behavioral rules. The following rules apply to all monsters, unless stated otherwise.

Movement
Monsters generally try to close in on their target via the shortest possible route. If the direct route to the target is blocked by a wall or a solid thing that the monster walks into, it randomly picks another direction to move in for a short while (to find another route to its target) until it reverts to heading straight toward its target again. When the monster reaches its target and bumps into it, it will move away from it for a while in a similar fashion it does when hitting any other obstacle (unless it has a melee attack, in which case it will engage the target with it).

Choosing target
A monster chases one target at a time. The monster's initial target is usually the player who awakened the monster from its dormant state by moving into its line of sight or by making an attack in an area the monster can hear. If the initial target was another monster and the monster has not perceived a player while fighting the other monster, it returns to the dormant state after killing its target monster.

After a monster awakens from its dormant state and it is hit for the first time, a target countdown timer called "threshold" is activated. The longer a monster walks around with the same target, the lower the threshold gets. As long as the threshold remains positive, the monster will not change its target even if it is hit by another player or a monster. If the threshold reaches zero, the monster may choose a new target to chase if it is hit by another monster or player or if it perceives another player. Note that this is only a possibility, and often the monster will choose to ignore the hits it takes and keep its current target even if its threshold is at zero. The threshold system does not apply to the Arch-Vile, which changes its target immediately to the player or monster that hurts it.

Monsters will only choose another monster as their target if it accidentally hits them with an attack. Arch-Viles can never be the target of another monster, nor can Pain Elementals, as the Lost Souls launched by a Pain Elemental are targeted instead.

Ranged attack use
The further a monster is from its target, the more it will use its ranged attack (if it has one), and the closer, the less. The logic behind this is, that when the monster is in close proximity of its target, it will try to get to its target faster to be able to hit it with its melee attack.