Game AI development

All services

Artificial Intelligence or AI development for game

Game AI development is the most complicated thing in video games. The game mechanics are way simpler to code: if player does X, then game does Y. But the AI must have an ability to decide what to do after every action taken by the player.  It’s way harder than it seems, because the AI must control dozens of independent entities at the same time.

ai drone

Basically, there are three types of AI: board game rival, allied NPCs and enemies. Every type needs its own approach and logic to make it fun to play versus bots. We  have experience with game AI development and want to tell you how does the AI in game works.

The purpose of game AI

The game is fun when the player faces challenges and learns how to pass them. Those challenges may be difficult puzzles, impossible jumping sequences in platforming games or fight with multiple enemies at once. The harder the challenge the more satisfaction will the player get after beating it.

ai fight

The goal of game design is to make difficulty of those challenges correspond to the players level of skill. The game designer can easily adjust difficulty of puzzles or platforming levels, but when it comes to fights he needs to work with AI.

The first purpose of game AI is to make player feel emotions:

  • fear of failure;
  • anger from failed try;
  • satisfaction from winning the fight.

To achieve this the AI must be smart. The player must take every fight as a risky challenge and not as a shooting practice with moving targets. There is a good joke about duelist talking with his second:

— How accurately can you shoot? 

— I can hit an apple from 20 steps away.

— And what if the apple will be aiming a pistol at you?

To get satisfied player must feel that he did all right and has beaten a strong opponent and not some dumb bots.

ai making the game fun

The second purpose of game AI is to prepare the player to the multiplayer part of the game. The AI must force the payer to use and become familiar with all gameplay mechanics like covers and grenades.

And the third purpose is to nicely succumb to the player. Fighting a smart AI is fun until you lose because of perfect aim and reactions of an AI.

How does the game AI works

To make explanation simple we will call an AI controlled entity a bot. 

The game AI works in cycles. One cycle consists of 3 steps:

  • sense — detect what was changed in a game world;
  • think — make a decision about it;
  • act — do the decided thing.

In most of games the cycle repeats for every frame. This way the AI can respond to every player’s action and doesn’t freeze every few moments.

How AI sees the player

To make a decision AI must collect information about current state of the game world. AI may use bot’s eyes, ears or some specific senses. Also bots can communicate with each other, use security cameras “eyes” and ai capsule

To collect information about the player the AI uses so called capsule. A capsule is an area around particular bot. If the player is inside this area the bot will “sense” the player: AI knows that the player is near, but doesn’t react to it.

The capsule helps to save some computing power. If the player is not in the bot’s capsule, the game will disable most of AI features like sight and hearing.

So, the AI always know where the player is and the bots know too. But they do not “see” the player like we see things in real world. Instead of this the AI knows that the player is in bot’s field of view and just waits a few seconds before reacting to it. In stealth games it works the same way, but the AI calculates how good the player has hidden, is it possible to “see” him and how much time the bot must peer into shadow before “seeing” the player. If the shadow is too dark the AI will think “OK, there is the player, but he is in a shadow, so I can’t see him”.

The hearing is slightly less complicated. The bot can hear sound from any direction, but still must turn around and see the player to gain information.

Other “senses” may be magic auras, security cameras, traps, evidence like open doors or broken glass.

game ai seeing

And if the AI saw the player it doesn’t have to pretend that it doesn’t know where the player is.

How AI thinks and acts

There is no artificial intelligence, only many of “IF, THEN” statements that form a decision tree. Thinking phase is the complicated part because the programmer needs to fit every possible situation into strict rules.

In the thinking phase the AI processes the information he gained from the sense phase and makes a decision. For example, if the bot saw something suspicious, AI have to decide to stop and “stare” for a second to give the player a chance to escape.

game ai making decision

The fun begins in the moments of open combat. When the AI knows where the player is it must command the bots to move, shoot, flee, use their equipment or something else. It would be very strange if the dozen of bots will be acting simultaneously, for example, throw grenades at the same moment. To avoid this programmers use marks, sectors and other tricks.

For the AI the first thing to decide is to place the bots around the player. The game AI divides the area around player into sectors and commands the bots to take free sectors. By doing this the bots evenly spread around the player trying to not take position behind the player.

game ai enemy placement

Second thing to decide is to make bots attack the player and still give him chances to win in 10 vs 1 situations. There are two conditions: do not kill the player in all-on-one attack and give him periods to respond the attack. To achieve this the game AI uses marks. First bot to take a proper position can attack the player and if it lands a shot it applies a mark to the player. After few seconds the mark expires and other bot can take their turn to attack and apply the mark. By doing this the programmer is sure that bots will attack in turn and not kill the player with bulletstorm.

To spice things up the programmer can add a mark limit. For example, if the limit is set to 2, then only two bots can attack the player at the same time before one of the marks expires. While the player has a maximum amount of marks the other bots may change their position, call for help or do other things to make an illusion of life.

game ai attack marks

Different attacks can have their own marks cooldown. For example, “shoot” mark expires in 2 seconds and “grenade” — in 15 seconds. Shoots are less of a threat than grenades and the player will mostly shoot back and sometimes run from a grenade.

When the player has all the marks and the bots are waiting for marks to expire the AI switches to other options like changing position or taking cover. This actions work with sectors and depend on the game. For example, if the player has a sniper rifle with piercing bullets it will be fun to make bots intentionally line up in one sector and be killed by one bullet.

Few secrets of game AI development

The bots do not know about each other. You can see how bots stuck in doors, shoot through each other or hinder their allies in almost every game. That’s because every modern game AI doesn’t tell the bots to interact with each other, so they always act like a group of individuals.

The AI tries to place bots in the player’s field of view. It is made so the player will see possible threats and react to them. And if the player dies, he can only blame himself and not the cowardly AI shooting his back.

In the open world games AI always work with every bot and NPC. The only difference between the bots near the player and bots far away is that the last aren’t rendered by graphics card at the moment.

The difficulty level can be controlled with marks and sectors limit. On “Hard” there can be 5 bots attacking at the same time, on “Easy” — only 2, while other are sitting in cover.


The AI can intentionally send bots to patrol to the location where the player currently is. Remember that AI always knows where the player is but pretends not to. By doing this programmers can give to the player more thrilling experience and create constant action in open world game.

Sometimes game designer can disable marks and sector limits to make game even harder. For example, there is no limit for simultaneous attacks in Dark Souls series. And the player can die in one second because dozen of archers decided to shoot at same time.

Other kinds of AI in games

We described game AI for 3D action games. There are different kinds of AI in 2D platformers, turn based strategies and racing games, but they use the same cycle: sense, think and act.

In racing games the AI calculates it’s route and speed based on obstacles ahead. To make bots look like real people the AI does precise calculation for some bots and almost no calculation for others. As a result, some cars avoid all the obstacles and finish first, while the other crash at the start.

racing game ai

In 2D platformers AI behaves like script with some kind of randomness. For example, the bot can only move forward and then fall from ledge. If the bot can move in any direction and attack by itself, the AI will command it to attack whenever the player is in range.

In strategy games AI have it’s schedule and the decision tree. For example, to charge the player’s base if there are more than 20 troops produced or to produce only the troops which counter the player’s army seen by the bot.

Game AI development to order

We can develop a game AI for every game genre: 3D action, 2D platformer, first person shooter or racing game. If you want to develop card or board game with unique mechanics — we will help you to create AI controlled opponents and set up their difficulty level.

Our programmers work with game designers to make the AI do it’s best in any game situation. By doing this we can be sure that the game will fill as a complete product.

Keep in touch:
+44 7 44 55 3 66 31

Send us a message via messenger or email