💀

Doom's Enemy AI and Behavior

Jul 11, 2024

Doom's Enemy AI and Behavior

Introduction

  • Doom's monsters are simple: approach and attack the player, take damage, and die.
  • Despite their simplicity, their behavior is quite elegant.

Monster Definitions

  • Hard-coded in the engine:
    • Collection of data containing indices to various enemy states:
      • Spawn state: When idle.
      • See state: When chasing a target.
      • Pain state: When they play a pain animation and sound.
      • Melee state: For melee attacks.
      • Missile state: For ranged attacks.
      • Death state: Death animation and sound.
      • Ex-death state: Extreme death animation.
      • Raise state: Animation when resurrected.
  • Example: Revenant
    • Spawn state index: s_skel_stand
    • Function: A_Look - constantly checking for player sounds and positions.

Nightmare Difficulty Differences

  • Reaction time: Always starts at 8 unless it's Nightmare difficulty.
  • Nightmare Mechanics:
    • Faster reaction times.
    • Faster enemy speeds: Turbo pinkies, faster projectiles.
    • Different attack patterns.

Enemy Wake-up Mechanism

  • Enemies wake up by checking for player sounds in sectors.
  • Ambush flag: Keeps enemies idle despite hearing sounds.
  • P_LookForPlayers: Scans if players are alive and in sight.

Enemy Chasing Behavior

  • See state: Defines enemy chasing behavior using A_Chase function.
    • Update angle and direction.
    • Check for melee attacks if within 64 units.
    • Attempt ranged attacks if conditions are met.
  • Movement Mechanics:
    • Use P_NewChaseDir: Calculates shortest path to the player.
    • Bumping into obstacles leads to recalculating path.

Attacking Behavior

  • Melee Attack: Perform if player is within range.
  • Missile Attack: Conditions for ranged attacks, e.g., line of sight, distance.
  • Reaction to Pain: Counter with projectile attacks.

Damage and Death Mechanics

  • When harmed: Calls P_DamageMobj function.
    • Lost Souls reset momentum.
    • Pain states activate based on pain chances.
  • When health drops to zero: Calls P_KillMobj.
    • Checks whether to play death or ex-death animation.
    • Boss death triggers special actions.

Resurrection and Wake-up

  • Corpse respawn on lighter difficulties if certain conditions are met.
  • Arch-vile resurrection involves reversing death animation.

Lost Souls Specifics

  • No wake-up sound.
  • Spawn limit of 21 to prevent overload.
  • Unique physics during charging and collision.

Conclusion

  • Comprehensive overview of Doom's enemy behavior.
  • Acknowledgments to various supporters and contributors.