Difference between revisions of "Monster behavior"

From DoomWiki.org

[unchecked revision][checked revision]
m (Choosing target: caps)
(Movement)
(17 intermediate revisions by 12 users not shown)
Line 1: Line 1:
 
[[Monsters]] in the [[Doom engine]] games have a primitive [[Wikipedia:Game artificial intelligence|artificial intelligence]] that follows a set of behavioral rules. The following rules apply to all monsters, unless stated otherwise.
 
[[Monsters]] in the [[Doom engine]] games have a primitive [[Wikipedia:Game artificial intelligence|artificial intelligence]] that follows a set of behavioral rules. The following rules apply to all monsters, unless stated otherwise.
  
 +
==Initial state and alertness==
 +
When the map is loaded, all monsters spawn in the idle state. Idle monsters are stationary and appear to be walking in place. This is because Doom monsters have no idle frames, instead going through their first two walking frames in a loop.
 +
 +
An idle monster looks in a 180-degree cone towards the direction of its initial orientation<ref name="doomsrc1">[[Doom source code]], p_enemy.c</ref>
 +
. The monster's initial target is usually the [[player]] who awakened the monster by moving into its line of sight, by making an attack in an area the monster can hear, or by harming the monster. If the initial target was another monster and the monster has not perceived a player while fighting the other monster, it [[Monsters may target players without ever seeing or hearing them|will usually]] return to the idle state after killing its target monster.
 +
 +
In addition, a monster may have the [[Thing#Flags|"ambush" flag]] set onto its map [[thing]], called {{c|MF_AMBUSH}} in the [[source code]], and sometimes erroneously referred to as a "deaf" flag. An ambush monster can still hear the player but it will not become active, instead going into the "state of full spatial alertness". In this state, the monster awakes when it has a direct line of sight to the player, even without the need to face him directly<ref name="doomsrc1" /> (by means of a simple line-of-sight check performed between two [[mobj]]s).
 +
 +
==Choosing and switching targets==
 +
A monster always chases one target at a time. Monsters will only [[monster infighting|choose another monster as their target]] if it accidentally hits them with an attack. [[Arch-vile]]s can never be the target of another monster, nor can [[pain elemental]]s, as the [[lost soul]]s launched by a pain elemental are targeted instead.
 +
 +
If the monster's current target is another monster, it almost always turns on the player after it is done with its current enemy, and monsters resurrected by arch-viles almost always immediately turn on the player. Lost souls damaged by other monsters forget their targets after a single counterattack, whether it was successful or not.
 +
 +
==Targeting threshold==
 +
After a monster awakens from its idle 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. The monster will only choose a new target if the threshold reaches zero and the monster is hit by another monster or player, or if its current target dies. The threshold system does not apply to the arch-vile, which changes its target immediately to the player or monster that hurts it.
 +
 +
The base threshold counter is set to 100 [[tic]]s, or about 3 seconds<ref name="doomsrc2">Doom source code, p_inter.c, p_local.h</ref>.
 +
 
==Movement==
 
==Movement==
Monsters can move in any [[Wikipedia:Cardinal_direction|cardinal]] or [[Wikipedia:Ordinal_direction|ordinal]] direction.
+
Monster movement system can be generally described with several rules<ref name="mov1">Gipson</ref>:
 +
 
 +
*Monsters can move in any [[Wikipedia:Cardinal_direction|cardinal]] or [[Wikipedia:Ordinal_direction|ordinal]] direction.
 +
*Monsters are blocked by walls and other impassable objects, including other monsters.
 +
*Floor elevation changes must not exceed 24 [[unit]]s between any two adjoining sectors.
 +
*The difference in height between the floor and ceiling must be ''equal or greater than'' the monster's height.
 +
*The open space between walls and other impassable objects generally must be significantly wider than the monster. Because the monster moves by trying to "step" a certain distance in a given direction, it generally cannot navigate very tight spaces, since it will tend to "overshoot" into an adjoining wall and the movement check will fail.
 +
*While monsters can ascend stairs, they can only do so if the stair's rise is shallow enough - the stairs must not rise more than 24 units per the amount of the monster's width. This is because the engine checks for the highest floor touching any portion of the spot where the monster wishes to move, and fails the movement if it is more than 24 units above the monster's current floor height.
  
 
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.
 
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.
  
If a monster with no melee attack 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.
+
In their pursuit, monsters will try to open doors and activate lifts, except for those marked as player-only, however sometimes they [[Monsters open locked doors|succeed in that also]]. In addition, they have difficulties when trying to [[Monsters stuck in doortracks, walls or hanging off lifts|open an already opened door]].
  
If a monster has no target, it is in the dormant state and will not move.
+
A monster does not need to have a line of sight to follow its target, and will attempt to close in on its position within the level.
  
==Choosing target==
+
If a monster has no target, it is in the idle state and will not move.
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.
+
==Flying movement==
 +
Monsters with the ability to fly ([[cacodemon]]s, [[pain elemental]]s and [[lost soul]]s) are generally subjected to the rules above, except since they do not walk, they are not hindered by steps and dropoffs. Still, they obey additional restrictions<ref name="mov1"/>:
  
Monsters will only choose another monster as their target if it accidentally hits them with an attack. [[arch-vile]]s can never be the target of another monster, nor can [[pain elemental]]s, as the [[lost soul]]s launched by a pain elemental are targeted instead.
+
*A flying monster can only fly ''as high as the highest height it has been on''.
 +
*A flying monster can gain new altitude (rise higher than its starting altitude) ''by "climbing up" against the obstacle'', e.g. a decoration or the linedef between the two sectors of different heights. If said linedef is set to block monster movement, the monster will ''not be able to gain altitude at all''.
 +
*A flying monster can only change elevation as fast as its base movement speed.  
  
==Ranged attack use==
+
It should be noted that attacking lost souls move like [[projectile]]s and are not subject to these mechanics. In all other respects, they follow these patterns.
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.
+
 
 +
==Melee and ranged attack use==
 +
When the monster wakes up upon seeing or hearing the player, it will delay its first attack by at least 8 tics (called ''reactiontime'' in the code). If aroused by damage, or when playing on Nightmare! [[skill level]], ''reactiontime'' is set to zero, making it attack right away without any delay.
 +
 
 +
The further a monster is from its target, the less it will use its ranged attack (if it has one), and the closer, the more. This way the monster will close in on its target, where it can score more successful hits. At long distances, [[spiderdemon]]s and lost souls in particular have higher attack probability than other monsters; for [[cyberdemon]]s, the probability is even higher.
 +
 
 +
While hitscans cease to trace after 2048 map units, this does not prevent monsters with bullet attack to aim and shoot at their targets beyond this range. Arch-viles will not target enemies further than 896 units away.
 +
 
 +
After attacking, the monster will make at least one move before attacking again, compelled by the game logic. On Nightmare! or when the <tt>-fast</tt> [[parameter]] is used, this constraint is omitted, making the monster shoot as long as its target stays in sight, unless it flinches after being hit.
 +
 
 +
The monster will use its melee attack if the distance is less than 64 units. [[Revenant]]s are hardcoded to attack only in melee when in range of 196 units, however they still must get closer than 64 units to administer a punch.
 +
 
 +
If a monster with no melee attack reaches its target and bumps into it, it will move away in a random direction in a similar fashion it does when hitting any other obstacle.
  
 
==See also==
 
==See also==
*[[Lost Soul charging backwards]]
 
 
*[[Monster infighting]]
 
*[[Monster infighting]]
 
*[[Monsters fleeing]]
 
*[[Monsters fleeing]]
 +
*[[Monsters stuck in doortracks, walls or hanging off lifts]]
 +
*[[Monsters open locked doors]]
 +
*[[Flawed collision detection]]
 +
*[[Stairs that can be ascended, but not descended]]
 +
*[[Lost soul charging backwards]]
 +
*[[Lost soul colliding with items]]
 +
*[[Lost soul target amnesia]]
 +
*[[Baron attacks a monster behind him]]
 +
 +
== Sources ==
 +
*[http://www.trilobite.org/doom/flight.html Monster Flight Rules], by Richard Gipson
 +
*[http://www.trilobite.org/doom/doom_metrics.html Doom Metrics], by Scott Ampoker
 +
*[[Unofficial Doom Specs]], by Matt Fell
 +
 +
==References==
 +
<references/>
  
 
[[Category:Doom engine]]
 
[[Category:Doom engine]]
 
[[Category:Monsters]]
 
[[Category:Monsters]]

Revision as of 09:56, 18 April 2016

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.

Initial state and alertness

When the map is loaded, all monsters spawn in the idle state. Idle monsters are stationary and appear to be walking in place. This is because Doom monsters have no idle frames, instead going through their first two walking frames in a loop.

An idle monster looks in a 180-degree cone towards the direction of its initial orientation[1] . The monster's initial target is usually the player who awakened the monster by moving into its line of sight, by making an attack in an area the monster can hear, or by harming the monster. If the initial target was another monster and the monster has not perceived a player while fighting the other monster, it will usually return to the idle state after killing its target monster.

In addition, a monster may have the "ambush" flag set onto its map thing, called MF_AMBUSH in the source code, and sometimes erroneously referred to as a "deaf" flag. An ambush monster can still hear the player but it will not become active, instead going into the "state of full spatial alertness". In this state, the monster awakes when it has a direct line of sight to the player, even without the need to face him directly[1] (by means of a simple line-of-sight check performed between two mobjs).

Choosing and switching targets

A monster always chases one target at a time. 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.

If the monster's current target is another monster, it almost always turns on the player after it is done with its current enemy, and monsters resurrected by arch-viles almost always immediately turn on the player. Lost souls damaged by other monsters forget their targets after a single counterattack, whether it was successful or not.

Targeting threshold

After a monster awakens from its idle 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. The monster will only choose a new target if the threshold reaches zero and the monster is hit by another monster or player, or if its current target dies. The threshold system does not apply to the arch-vile, which changes its target immediately to the player or monster that hurts it.

The base threshold counter is set to 100 tics, or about 3 seconds[2].

Movement

Monster movement system can be generally described with several rules[3]:

  • Monsters can move in any cardinal or ordinal direction.
  • Monsters are blocked by walls and other impassable objects, including other monsters.
  • Floor elevation changes must not exceed 24 units between any two adjoining sectors.
  • The difference in height between the floor and ceiling must be equal or greater than the monster's height.
  • The open space between walls and other impassable objects generally must be significantly wider than the monster. Because the monster moves by trying to "step" a certain distance in a given direction, it generally cannot navigate very tight spaces, since it will tend to "overshoot" into an adjoining wall and the movement check will fail.
  • While monsters can ascend stairs, they can only do so if the stair's rise is shallow enough - the stairs must not rise more than 24 units per the amount of the monster's width. This is because the engine checks for the highest floor touching any portion of the spot where the monster wishes to move, and fails the movement if it is more than 24 units above the monster's current floor height.

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.

In their pursuit, monsters will try to open doors and activate lifts, except for those marked as player-only, however sometimes they succeed in that also. In addition, they have difficulties when trying to open an already opened door.

A monster does not need to have a line of sight to follow its target, and will attempt to close in on its position within the level.

If a monster has no target, it is in the idle state and will not move.

Flying movement

Monsters with the ability to fly (cacodemons, pain elementals and lost souls) are generally subjected to the rules above, except since they do not walk, they are not hindered by steps and dropoffs. Still, they obey additional restrictions[3]:

  • A flying monster can only fly as high as the highest height it has been on.
  • A flying monster can gain new altitude (rise higher than its starting altitude) by "climbing up" against the obstacle, e.g. a decoration or the linedef between the two sectors of different heights. If said linedef is set to block monster movement, the monster will not be able to gain altitude at all.
  • A flying monster can only change elevation as fast as its base movement speed.

It should be noted that attacking lost souls move like projectiles and are not subject to these mechanics. In all other respects, they follow these patterns.

Melee and ranged attack use

When the monster wakes up upon seeing or hearing the player, it will delay its first attack by at least 8 tics (called reactiontime in the code). If aroused by damage, or when playing on Nightmare! skill level, reactiontime is set to zero, making it attack right away without any delay.

The further a monster is from its target, the less it will use its ranged attack (if it has one), and the closer, the more. This way the monster will close in on its target, where it can score more successful hits. At long distances, spiderdemons and lost souls in particular have higher attack probability than other monsters; for cyberdemons, the probability is even higher.

While hitscans cease to trace after 2048 map units, this does not prevent monsters with bullet attack to aim and shoot at their targets beyond this range. Arch-viles will not target enemies further than 896 units away.

After attacking, the monster will make at least one move before attacking again, compelled by the game logic. On Nightmare! or when the -fast parameter is used, this constraint is omitted, making the monster shoot as long as its target stays in sight, unless it flinches after being hit.

The monster will use its melee attack if the distance is less than 64 units. Revenants are hardcoded to attack only in melee when in range of 196 units, however they still must get closer than 64 units to administer a punch.

If a monster with no melee attack reaches its target and bumps into it, it will move away in a random direction in a similar fashion it does when hitting any other obstacle.

See also

Sources

References

  1. 1.0 1.1 Doom source code, p_enemy.c
  2. Doom source code, p_inter.c, p_local.h
  3. 3.0 3.1 Gipson