Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
Blastfrog

How to make better AI

Recommended Posts

I really want to recreate the more clever/less dumb as a brick AI as seen in other FPS games in ZDoom, like the AI in Blood (the general movement of those enemies), Deus Ex's AI, etc.

I'm most interested in Build's AI though. Does anyone know the exact workings of it (when and why it decides to start strafing, move backwards, etc).

I'm most concerned about actual monster movement though, I don't want monsters to wander in the player's general direction, I want to know how other games handle enemy movement.



Note that I'm not asking for coding help, I'm asking if anyone has any clue what makes better AI's tick so that I can emulate it's methods.

Share this post


Link to post

Mmmm. I always found that fighting an incredible amount of dumb things is often a lot more enjoyable than a few single hard things.

Share this post


Link to post
40oz said:

Mmmm. I always found that fighting an incredible amount of dumb things is often a lot more enjoyable than a few single hard things.


*nods*

That said, Deus Ex's AI is fairly worse than Doom. Enemies run in a straight line to you (except when they're hurt and just run away aimlessly), and often get stuck in walls.

Share this post


Link to post
Phml said:

*nods*

That said, Deus Ex's AI is fairly worse than Doom. Enemies run in a straight line to you (except when they're hurt and just run away aimlessly), and often get stuck in walls.


They also circle strafe you, which I find hilarious.

Share this post


Link to post
40oz said:

Mmmm. I always found that fighting an incredible amount of dumb things is often a lot more enjoyable than a few single hard things.

I don't want to make the enemies super-intelligent or anything, I just want them to do a little more than just wander aimlessly and shoot. The reason for this being, I've wanted to enhance the AI in TSAT for some time, simply because it somehow feels wrong for all the marine enemies to be as dumb as a brick.

Basically, I want to have them just move a little more dynamically. I want to know when the AI should decide to strafe, circle strafe, or move backwards. Otherwise, the AI would remain largely the same.

Share this post


Link to post

There's a friendly marine mod for ZDoom, sometimes called "coop bots". You could look at their coding.

Share this post


Link to post

There's a thousand ways to design an AI. One very simplistic model is to have a list of possible actions that the monster may perform in certain states, and it picks a new action randomly whenever the current one terminates. For instance, lets say you have a monster "BadGuy" with the following states: "Idle", "Target visible", "Target lost."

These states would have the following actions:
Idle: "Do nothing"
Target visible: "Shoot", "Chase", "Strafe", "Retreat"
Target lost: "Search", "Ambush", "Return to idling spot"

The BadGuy would begin as idle, and does nothing since that's the only available action. As soon as the BadGuy sees you, it randomly chooses to "Chase", walking a few steps forward. After that, it randomly chooses to "Shoot", then "Strafe", etc. Every time it chooses to move it would choose a target spot on the map to move to based on whatever logarithm you have implemented. As soon as you would move out of sight the BadGuy would enter the "target lost"-state, and it would decide to "Search" for a while, after which it would decide to "Return to idling spot."

If you want to add actual intelligence instead of randomly picking actions to perform...well, just replace the rng with your own custom intelligent logarithm. :P

Share this post


Link to post
40oz said:

Mmmm. I always found that fighting an incredible amount of dumb things is often a lot more enjoyable than a few single hard things.

No shit.

I still have an old html of the to-do list from Doom Legacy's home page with a list of features they would not implement in Legacy. One of them was having a better AI for monsters.

They said the reason for that was, "Monsters are NOT intelligent, they're just cannon fodder." I couldn't agree more. ;)

Share this post


Link to post
Sodaholic said:

I'm most interested in Build's AI though. Does anyone know the exact workings of it (when and why it decides to start strafing, move backwards, etc).

Grab the .con files for Redneck Rampage, there are separate files for each enemy containing their AI script.

Share this post


Link to post

The AI in most games is deterministic/mechanistic aka it essentially follows a few basic rules and/or a script, because it's straightforward to code and predictable enough to design.

Plus, you can always just let the AI play with different rules than the player, by simulating the fact that e.g. a novice player feels as if superior opponents actually cheat or are always a step (or more) ahead of them. E.g. FPS AI can actually see through walls, while e.g. CS noobs may feel as if "1337" players can do the same.

More sophisticated ones may incorporate some sort of learning/training system based on Machine Learning techniques, but apart from a few notable examples (e.g. Rise of the Robots), this has not caught on. Not every development team can afford to hire a Ph.D. in Artificial Neural Networks/Machine Learning (ANN/ML), let alone that finetuning such systems is a bitch, and they are almost never computationally efficient enough or easy to integrate into games compared to a deterministic/programmatic approach. When was the last time you heard of a game-industry-standard, high-performance ANN or ML package?

Share this post


Link to post

It was said about Descent that it has intelligent (but rather slow) robots. It did happen twice or thrice that the robot decided to hide someplace to attack me later (when I least expect).

Share this post


Link to post

The main problem I've heard about having clever AI is that, particularly in a first-person perspective, you don't see them being clever and you don't see their reasoning. What you see is an enemy randomly disappearing back down a corridor only to appear out of nowhere and bumrape you later.

If you know that they are meant to run and hide or run off for reinforcements before coming back to try and ambush you then it may make sense, but how are you going to know that's what they're doing? These days the default solution to this problem is just to have the AI shout out what they're up to ("dog barking" is an industry term for this).


Plus, let's face it, a lot of players wouldn't handle it very well if the AI was genuinely clever and were successfully outflanking and ambushing him. A lot of us games programmers would love to do that sort of thing, but it's not a popular choice, so we're left cracking together some quick Behaviour Trees or Finite State Machines and then getting sent back to work on making sure the physics and scripting stuff works better so the games designers can have the enemies all run to a point and spam grenades everywhere with proper parabolic arcs.

Share this post


Link to post
Phobus said:

("dog barking" is an industry term for this)


Is this why almost every first person shooter makes the people scream "RELOADING!!!" every time they reload their gun?

Share this post


Link to post

Deus Ex's AI


If you call an MJ12 soldier standing still for a full 30 seconds after his teammate was just killed and then proceeding to run into and get stuck on the nearest counter, then yeah. Deus Ex's AI is amazing.

Phml said:

*nods*

That said, Deus Ex's AI is fairly worse than Doom. Enemies run in a straight line to you (except when they're hurt and just run away aimlessly), and often get stuck in walls.


I loved watching the shootout in Hells Kitchen because it was just so unbelievably terrible. The characters just seemed to run around randomly firing their assault rifles (one handedly I might add, which made it look even worse) until they ran out of ammunition in which case they'd just run through the enemies' fire with knives.

40oz said:

Is this why almost every first person shooter makes the people scream "RELOADING!!!" every time they reload their gun?


Kind of an important thing to let your teammates know in the heat of combat actually (you'd probably know that already if you had actually bothered to read any of the replies). It is kind of stupid when they scream it when they're on their own. What really bothers me is when enemies loudly announce that you wiped out their team and that they're alone (see the replicants in FEAR announcing "I'M ALL ALONE HERE" for an example).

Share this post


Link to post
Phobus said:

These days the default solution to this problem is just to have the AI shout out what

Which brings the first idea of AI improvement in OP's mod: make monsters call for help. That will make nearby monsters discard whatever they're doing and "hate" the enemy of the shouter, possibly with some berserk modifications.

Share this post


Link to post

Soldier of Fortune had some pretty tough AI, but IMHO it fell clearly into the "few hard enemies are less fun than a fuckton of dumb grunts" case, exactly because it was so good.

Enemy soldiers could move in ways you simply couldn't (they could switch from running to a careful ducked-crawl in an instant), they exposed themselves only very minimally behind cover to shoot you, and some were so nimble that they did sommersaults and evasive rolls at close range to avoid your crosshairs!

At higher difficulty levels, you had the impression that the player was controlling a wheelchair-bound cripple or a stiffened mummy, while enemy AI was literally nowhere to be seen (other that peeking for a moment behind cover to shoot at you with 100% accuracy), or, when you saw them, they simply outmaneuvered and outsmarted you.

I think players simply don't want that kind of AI: it's more important for the AI to appear smart than to actually be as good as it can. Otherwise, it's really easy to program it in such a way that it outperforms humans in terms of reflexes, precognitions, endurance and perseverance.

Imagine that you code a very intelligent learning "commando" type AI for a tactical FPS, which starts off entirely noobishly but soon starts copying the player's tactics, and performing them better and more efficiently than him: soon the player will get his ass handed to him and will look for ways to tone it down.

You could get the same result simply by making the AI a cheating bastard, and letting it know where the player is, snipe at impossible distances, etc., a performance it would have eventually reached anyway with a super-intelligent ML/ANN approach, but at a greater expense for the developers.

Share this post


Link to post
Maes said:

You could get the same result simply by making the AI a cheating bastard, and letting it know where the player is, snipe at impossible distances, etc., a performance it would have eventually reached anyway with a super-intelligent ML/ANN approach, but at a greater expense for the developers.


First thing that came to mind for me was STALKER's AI which pretty much had night vision and an uncanny ability to score perfect headshots from any distance.

Share this post


Link to post
Craigs said:

First thing that came to mind for me was STALKER's AI which pretty much had night vision and an uncanny ability to score perfect headshots from any distance.


Well, you don't even need to go farther away from Quake 3 Arena: OK, maybe bots are considered merely "noob training material", but they can still pull stuff like sniping you without there being mutual visibility. The final fight with Xaero is particularly infamous.

OK, so maybe a super-1337 player can develop pixel-sharp shooting reflexes and "frag noobs" just as well as Xaero, but to any player of lesser skill there won't be any difference between being fragged beyond visual range by someone who wasted 1000 hours of his life to get that good, by an intelligent AI or simply by a purely mechanically aiming AI.

Similarly, in an RTS game I don't care if I get zerged by a human player who is really so skilled as to ourproduce me by a significant marging, or by an AI that can simply cheat and produce troops instantly: the final result will look the same to me.

Share this post


Link to post
40oz said:

Is this why almost every first person shooter makes the people scream "RELOADING!!!" every time they reload their gun?


That and, as Craigs pointed out, it is a fairly standard military procedure which is easy to reproduce. As a player it doesn't make much sense to me to have enemies do this, when it just tells me that they can't shoot back for a second and will be preoccuppied, thus making them an easy target.


Heh - seems we've all basically said the same thing in this thread. Numbers of dumb enemies is more fun because the clever ones own just as wall as an AI doing advantageous things the player can't do or a human player who's spent too long on the game.

Share this post


Link to post
printz said:

It was said about Descent that it has intelligent (but rather slow) robots. It did happen twice or thrice that the robot decided to hide someplace to attack me later (when I least expect).

You definitely need to play Descent 2 on Insane to appreciate the work that went into developing the AI for the series. Stuff like bots peeking out from behind a corner, noticing you and moving back to set up an ambush really does happen.

Probably applies to Descent 3 as well, but since I didn't have the patience to get through the first level on Insane I can't say much about it.

Share this post


Link to post

One addition to the AI system that may be interesting would be "chasepoints" that are placed at the last spot the monster saw you, so it goes to that point and mills around until it hears or sees you again. An extension of this could have each "point" actor watch you as you go further away and around another corner, placing point #2 at the next point, and so on. If the monster is more intelligent, it can track you down from point to point, giving up if you aren't heard in a few seconds or after a random number of points, reverting to aimless wandering or vanilla pursuit. This may get complex if a separate tracking trail is stored for every monster's pursuit of the player, so limiting the point number may be best.

Share this post


Link to post
Xeros612 said:

Doom with AI that's more intelligent than most players.... actually sounds kind of cool.


It's honestly how I think horror games should be done too. With a horror game where the monsters are dumber than the player, the player can take comfort in the fact that they're easily smarter than their enemies. In a game where the AI is highly inteligent, they can't.

Share this post


Link to post
phi108 said:

One addition to the AI system that may be interesting would be "chasepoints" that are placed at the last spot the monster saw you, so it goes to that point and mills around until it hears or sees you again. An extension of this could have each "point" actor watch you as you go further away and around another corner, placing point #2 at the next point, and so on. If the monster is more intelligent, it can track you down from point to point, giving up if you aren't heard in a few seconds or after a random number of points, reverting to aimless wandering or vanilla pursuit. This may get complex if a separate tracking trail is stored for every monster's pursuit of the player, so limiting the point number may be best.

In a path-node based navigation system, as seen at work in the various Unreal Tournament games, you already have the points in place to reference, so storing three or four pointers for where an AI thinks it's most likely to find the player again if it's lost them would be a simple case of an FOV check from the AIs standpoint followed by a run through a binary tree or map based crawl through the path node structure with range checks for the player. You could make this quicker if the player is storing a pointer to the path node that it's currently nearest, so the monsters just take that information from him instead, thus meaning the check for nearest node is only done by one object rather than many.

Even with a fair few AIs running around being clever those two checks won't take up much processing time or memory. You can always limit it to just one "last seen" pointer if you're worried about memory (pointers or ID tags really won't be memory intensive though), and update it every few frames or something if processing the information is becoming an issue.


I also agree that, if we're after an atmospheric game where the player is meant to feel completely outclassed rather than merely overwhelmed by numbers, having a really intelligent AI is the way to go.

Share this post


Link to post
40oz said:

Mmmm. I always found that fighting an incredible amount of dumb things is often a lot more enjoyable than a few single hard things.

When it comes to FPS shooters I tend to agree, I prefer Doom's no bullshit AI where the enemies run towards you and attack, instead of taking cover, trying to do complex tricks that usually don't even add to the difficulty anyway.

On the other hand I'm playing Skyrim lately, and AI glitches aside, the more complex AI here adds fits the experience nicely.

Share this post


Link to post

I once read a comment by John Romero. I forget exactly what he said but the gist was "if the enemies in a game had human-like AI, the game would be no fun because it would be like trying to play team deathmatch with you on one team and 100 people on the other".

That being said, the ability to fake some AI, to give the impression that enemies are thinking about their actions, would be nice.

Things that I think would look good in Doom:

Nearby enemies reacting to one of their number getting shot. Presently, two enemies can be standing right next to each other and, if the flags are set in a certain way, it is very common for the player to be able to sneak a shot at one of them (and kill him) without the second enemy reacting. By extension, this could also include enemies flooding to the point of attack to help defend (etc) their base.

Enemies running for cover, stopping and then attacking the player from a better position than they had before. No idea how such a thing could be implemented as a general behaviour.

Running away when wounded to a certain health (and possibly collecting health items?).

Enemies not automatically continuing towards the player once they are woken. In Doom, once an enemy knows you are there, he will keep trying to walk towards you. As a player, all you have to do is wait around a corner with your weapon ready and you know the enemy will walk around it sooner or later and you can just whack him as he does. In other games with more intelligent AI, enemies will often adopt the tactic that I just described for the player - ie they will go to a corner but not move in to view. They will just wait (with a chance that they may get "bored" with waiting and move out) and the onus is then on the player to move forward and flush the enemy out of their waiting places.



Of course, some (all?) of the above may be too difficult to believably achieve with Doom's pretty dumb AI. Also, I would suggest that the dumb animal AI of Doom is actually pretty appropriate for many of the Doom enemies. However, in a mod that is trying to create a supposedly intelligent enemy force (eg a WWII mod etc) then such abilities would be entirely appropriate.


Some little tricks that can work - but which have to be map specific:

Logan MTM had enemies be thrust sideways out of alcoves as the player approached in "Legacy of Suffering". This gave time impression of enemies strafing out of hidey-holes to ambush the player.

Monster patrol routes can give the impression of an intelligent enemy both by making it look as if they were doing something before they saw the player and by allowing them to not just break off and walk directly towards the player once the player has been spotted.

Pairing up enemies that are guarding a corridor so that if one gets killed, the other gets forcibly woken and set on the trail of the player even though he hasn't actually spotted the player himself.

Share this post


Link to post
Belial said:

You definitely need to play Descent 2 on Insane to appreciate the work that went into developing the AI for the series. Stuff like bots peeking out from behind a corner, noticing you and moving back to set up an ambush really does happen.

I assume that was feasible to program because Descent is a world made of cubes portalled together? Maybe something similar can be done in Doom by using the subsectors as map units (I had a thread about this and will work on it when I'm fed up with modding and don't have RL duties/interests).

Share this post


Link to post

Unreal Tournament series Ai hasn't been too bad for me. Sorian AI for Supcom FA and Supcom2 (especially 2) is pretty good too.

Share this post


Link to post
DeathevokatioN said:

When it comes to FPS shooters I tend to agree, I prefer Doom's no bullshit AI where the enemies run towards you and attack, instead of taking cover, trying to do complex tricks that usually don't even add to the difficulty anyway.


Complex AI done right can add a lot to the difficulty and fun value of the game. FEAR is a great example of this (enemies will try to flank you, point out your location to their teammates, tell them to shoot explosives near you, and sometimes try to quietly (and often successfully) sneak up on you when they're alone. The problem is that complex AI usually isn't done right these days. Nowadays developers are finding it easier and easier to get away with AI that basically boils down to hiding behinda a chest high wall, poking their heads out every now and then to pop off a shot, or if they couldn't see the player, toss a grenade in his general direction. It's kind of funny when you think about it. It's gotten to the point where this is sort of the standard for "complex AI".

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×