How Doom's Enemy AI Works

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
let's face it dooms Monster is primitive they tried to get close to you and perform an attack you shoot at them they could hurt and they die behind their simplistic behavior it's a fairly elegant system let's take a look how it works and also check out some other piece already at it first of all let's see how do monsters are defined there are pretty much hard-coded in the engine in the form of a collection of data each data collection contains indices to several enemy states the spawn states were an enemy is idle the sea state where an enemy is chasing down a target the pain state where the enemy will played a pain animation insult the mill a state that tells what to do when performing a melee attack the missile states that tells what to do when performing arranged the deck the death state will play the enemy's death animation and sound the ex death state of a played enemies teaming animation and the race state they will play the animation of an enemy getting resurrected let's take the revenant as an example it spawns state uses index s skeleton stand in this huge area of hard coded States go to the index we just picked here you can see a collection of values and functions let's quickly go through all of them SPR scale is the base index for the revenant sprite the zero afterwards means the frame offset this state must last for 10 ticks one take less 135th of a second so 10 ticks about 0.29 seconds this must call the a Luke function we'll get into that later the next action must be s scale stands to - the line below the last two values are unused so they're always zero what we just described was the first action of the revenant spawn state it consists of two actions where it cycles between two sprites making it walk in place when you start the new level enemies unloaded and place in the designated locations newly spawned enemies get their health type state etc from the hardcoded collection of data we saw earlier positions and angles are based on how the mapmaker place them one interesting thing here is its reaction time Direction time always starts at eight unless it's nightmare difficulty enemies never attack when the reaction time is greater than zero so that means enemies on neither difficulty will not hesitate attacking you when they wake up this is a fundamental difference between nightmares fast bounces and regular fast monsters which retain the default reaction speed another exclusive nightmare fast monsters mechanic art arrow pinkies and faster aim Kaku demon and baron projectiles the duration of the pink is state Herr Haupt and the projectile speeds were Imps Cacodemons and barons go from 10 10 and 15 respectively to 20 20 20 strangely enough the near doom release is like The BFG edition and potestas weird unity built don't have turbo pinks and faster projectiles anyway how exactly do enemies wake up looking at the revenant spawn stat again where it cycles between two sprites they've caused a look every 10 ticks let's see what this function does first checks if a player made a sound in this sector when a player fires a shot the noise is propagated through many sectors the sound keeps propagating under hits a dead end whether it be a wall a closed door or two sound blocking line deaths the sector will then mark the player as a target or make a sound if a sound target exists check the enemy's ambush flag this is often incorrectly called the death flag by the doom community but the ambush flag does is that the enemy remains idle even if it hurt a player shoot it also extends their field of fuel from 180 degrees to 360 so they'll wake up even with their backs facing you if a certain target exists and the enemy has no ambush flag then wake up and start chasing the player if the sector didn't register any sounds then call the P look for players function what this function does is scan for all players in the game for each player check if it's alive and if it's in sight if all conditions apply wake up and chase the player done if the player is not in the enemy's field of view but it's within sixty four units of the enemy's presence then wake up regardless now the enemy wakes up it'll play its wake up sounds imps and zombies at variations of a play randomly fully awake it's time to hunt down the player going back to the revenant states its sea state is s skeleton run one let's see what happens here it has 12 actions with each action lasting two ticks each sprite lasts four ticks in total and for every action causes the a chase function let's check it out each time a chase is called it decrements the enemies reaction time and threshold by one the threshold value is explained at the end fighting video so make sure to watch that video to fully understand how that works while we're moving make sure to update the enemies angle to the direction it's moving to if the enemy has no target anymore because it either died or disconnected look for a new one didn't find any then go back to the spawn state and show if we just attacked don't attack again unless it's nightmare difficulty or fast months are enabled instead of attacking so soon try to find a new direction to move to using P new chase dear go check out this function in just a moment up next we check if we can go for a melee attack if the enemy has a melee state is less than 64 units away from the player and the players in the enemy's line of sight then punch the living bejesus out of him using the revenant as an example again this state contains four actions there is the targets then next frame played a woosh sound effects advance to the next prides face a target again and then play the punch sound effects if within melee range if the enemy has a projectile attack and its move counters not zero yet then don't attack unless it's nightmare or fast monsters are enabled then don't give a crap and go wild well explain what the move counter is in just a minute before the enemy performs a successful projectile attack it must comply with quite a lot of conditions first of all if the target is not in sight then don't shoot the projectile if the enemy just played our pain animation then always attack back this is why revenants always to those annoying missile attacks also receiving a super shotgun blast to the face even if they are not a range here is the reaction time value again as long as it's not zero don't attack this value is always zero on nightmares explained earlier up next the game calculates the distance between the enemy and the player and then subtract 64 units from that number if the enemy lacks in melee attack then decrease the distance value by 128 units if the enemy is an arch foul and the distance is greater than 896 units then never initiate an attack if the enemy is a revenant and the distance is within 196 units then don't shoot missiles this creates a bit of a dead zone for the revenant where it will neither do it smelly attack nor missile attack unless he gets hurt of course if the revenant took player distance is greater than 196 units then half the distance value if the enemy is a cyberdemon spider demon or lost soul and also got the distance value in half now cap the distance value to 200 unless the enemies of cyberdemon then cap it at 160 generate and run a number between 0 and 255 and if this value is smaller than distance then don't shoot the projectile and bit of a misleading name missile states since it scanners are suited for ranged attacks speaking of which enemy hits can attacks are limited to 2048 units in length but will still attack from distances far greater than that also most enemies call a phase star between attack this ensures the enemies facing the player when attacking but the Barents and he'll announce it a bit of an oversight there are tech never calls a face targets to change targets right before the attack they'll toss a fireball from their behinds after performing a successful missile attack run the enemy's missile state and flag the enemy as one adjust effect let's see how the revenant does it this state contains four actions the first two will face the target and what de why are the frame offset so huge suddenly that's because the sprite rendering code masks the value of 32767 or 8000 index with the frame of sets if masked successfully then the sprite must be relative Fulbright's back to the a chase code if this is a co-op game the enemies threshold has been decreased is zero and it can see its current targets then look for new players if move gun decreased all the way to zero or head bumps into an obstacle then change the chase direction also randomly play a search side while chasing down the player anyway time to tackle the P new chase deer function this function will determine how the enemy must reach the player and is caught every time the move counter is zero to keep it simple start off by taking the shortest path towards the player either ordinal or directly forwards if the player ends up behind you turn around and move towards the player again the enemy will keep traversing this path onto the move counter equals zero then it will calculate the shortest path again and set the new random move counter value this is why enemies zigzag around when trying to approach you if the enemy cannot reach the player and walks past them and stick to this direction after the game allows you to turn if turning is possible turn either clockwise or counter clockwise if all fails then you're pretty bones and most likely stuck before the game advances the enemy's movement it calls a function called Pete try walk where it calculates the enemies next position if it detects an obstacle would be move and don't move the enemy there if the movement was successful set the new random wolf counter value so when is the movement not balanced obviously bumping into a warmer object stops the enemies movements also when the height difference between two sectors is 24 units or more unless it's a flying enemy of course but we'll get to them in a moment stairs are also a bit tricky taking the enemies total weight into consideration the difference between the highest and the lowest nut inside this width may not exceed 24 units either this is by a thinner enemies and walk stairs now this cannot unless you increase the width of the steps the game also checks if the enemy is not too tall for the other sector while moving enemies will always attempt to interact with doors if the enemies collision box crosses with the door then the door will open up the doors they can open our doors with special IDs 1 32 33 and 34 there's a bit of an oversight if the doors thin and a fast enemy bumps into the door some doors are marked for players only on one side so if the enemy coalition box touches that side it will open up the door a well-known example was Barney the arch fell from doom 2 is now 27 normally require a red key to open the exit door but the other side of the door is marked to be also opened by non players another oddities of enemies tend to get stuck at doors when they're inside the doors sector and they're angled towards and touching the door tracks they still register the special line that inside the sector they're stuck in but because the game sets their move direction to none during this process the condition here fails and they get stuck flying enemies don't check your drop-offs or too steep or nuts they don't change their height unless they bump into something then hitting an obstacle that were either descents or ascent depending what the new fluorides value is they've also flowed down if the target is getting too close and that is our enemies move around the level fairly simple but it works and isn't too taxing on the system now it's time to fight back what happens when you harm an enemy when you harm an enemy the function P damage and object is called let's see what happens here if the enemy you're harmed was a charging lost soul and reset all momentum back to zero if the enemy is a lightweight relative to the damage you've dealt is 64 units above you and dies then draw a 50% chance of the enemy falling forwards this is also by often lost souls are flung towards you and killed if the enemy's health - and damage dealt drops below zero call P kill and objects will get to the function in the moment if the damage does not go the enemy generate a random number and compared to the enemy's pain shots each enemy is hard-coded paint runs as high as one or sent for lost souls and as low as 3% or arch Falls if the render number is smaller than the paint chance and you're not a charging lost soul and run the enemy's pain states a flag indicating that the enemy was just hit this also sets as explained earlier this flag is used to throw enemies to counter with a projectile attack what does a pain state look like what interesting really using the revenant is an example again it contains two actions both use the same sprites last five ticks each and one cost the a paint function all this function does is play the enemies paint sounds after getting harmed Direction time is set to zero the next piece of code handles spent fighting stuff if an enemy is in its spawn states and gets damaged on the first idle frame then immediately retaliates however damaging the enemy on the second idle frame won't do anything normally shooting an IO enemy will wake them up because of sound propagation but let's assume there's a nut with sun block in line deaths and an enemy is facing their back to you you could potentially kill it without the enemy ever fighting back as long as she only damage the enemy on the second idle frame he won't retaliate that is of course as long as the paint chance as a traitor because I was at the enemy's state to the sea state anyway we mentioned earlier that dropping the enemies house below zero will call the P kill and object function if the dying enemy is not a lost soul then enable gravity this will cause calculus and painterly metals to drop like sex of potatoes the enemies height will also be quartered now it checks what kind of death state to play as mentioned in the chips video if the damage exceeds the negative of the enemies spawn off then run the exdeath states the example revenant has done so who play the regular death is dead what does the reference death state look like it consists of six actions the first two don't do much the third action caused a screw function where it plays its death sons if the dying enemies an aim for any of the three zombies and randomize the death sons if the dying enemies aspire to master mighdal cyberdemon they've played a death sound at full volume regardless of their position in the level back to the reverend again the fourth action caused a fall which sets the enemies of non-solid some enemies call a special boss death function at the end of the death animation this function checks a list of conditions if the dying animals had baron of hell and all barons are debts and the map is e1 and eight then lower all walls that are marked with tax 666 same with psy ready wasn't it to American Eve or of six when all siren events are dead in those maps then hence the net also inspired the masterminds III of AIDS and E for man doomed to Alcestis from f7 killing all manky by one lower all walls mark with text 666 killing all erica trans will raise steps mark with text 667 the letter smith flawed and responding enemies are enabled each time the last rocket run dies the step will race again self-locking enough this will also happen without responding enemies if you kill more than one a rocket run simultaneously the function will be called more than once raising the step too often now we're not done yet even dead and he still think on lightly difficulty each corpse will respond check every game tick the game checks if this corpse comes towards the kill percentage if it doesn't don't respond then it checks the difficulty or respond parameter if it's not neither difficulty or to respond power meters not set don't respond if the corpse hasn't been dead for these 30 seconds don't respond then every 31 ticks or 0.88 seconds there's a 1.5 percent chance is enemy will respond there's one more state to go through NIST array state when an arch foe resurrects a corpse the enemy's height will be restored by quadruplet and its half will be sent to the spawn health the enemy corpse will then run the race state let's take a look at our example revenant one more time it pretty much just plays its death animation in reverse and that's it arch fell resurrection is pretty complicated so I recommend to watch this channel Auto analysis video for more info and that's how enemies behave in doom there is one enemy however that is a bit of an outcast yeah lost souls are weird let's take a look why first of all they lack a wake-ups and second they can be spawned by the paint elemental because of this probably to prevent your ancient pc from getting overloaded there's a loss or limit of 21 and had pain elemental attempts to spawn a twenty second loss so nothing happens when they attack the game flags the masks all fly with this flag near physics get altered so when they charge it slam into a water object a momentum is set to zero even items blood loss salt acts when the loss all slams into a floor tear sets omentum gets inverted making them bounce when they slam into something the game sets their states to their spawn state this will call a look which means that if there's a sound target then the law saw immediately wakes up and starts chasing the player again however if no sound target exists then so stays asleep on to either make a sound or get in their line of sight but yeah that's it there's a lot to say about dues enemy AI so fully this was easy to understand thanks for watching and a massive thank you to Andrew Koval and really clean art Cox Austin been Filkins Brian C kappa [ __ ] Chris own you know a Tony Cyprian rusyn Curtis Carter e wolf de Guiche crew car Jeff Russell Joseph Coleman Joseph Jones Joshua Scoggins just in one kuba book Lloyd stats Lin wicked Moe built Mattias siberts Michael Dunn agua mister steal yo man Nolan Boyer quake gamer 6 3 2 richard Foster Roman era hope Sean Juan Sebastian Radcliffe Steven bone Steven holistic Ted Roddy this man Trevor Whelan turbine 2k v dot Thomas P Diddy xenia and liquid fusion I will be forever grateful for your support see you next time [Music] you [Music]
Info
Channel: decino
Views: 1,771,836
Rating: undefined out of 5
Keywords:
Id: f3O9P9x1eCE
Channel Id: undefined
Length: 16min 47sec (1007 seconds)
Published: Wed May 06 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.