Advice for Awesome Artificial Intelligence
Katherine Stull
02 / 21 / 18
Back to Blog
Artificial Intelligence or “AI” is the driving force behind making non-player character behavior responsive and realistic. This week, Rune: Ragnarok AI programmer Jack Bransky is sharing some of his tips and tricks on creating awesome AI in games.
Simplify, Simplify, Simplify
The key to good AI is to simplify it when you can. Player perception is top priority, and there are ways to create illusions that will make simple AI behavior seem complex. One example of this is in the Mario Kart franchise. When the player is racing far ahead of their AI opponents, the opponents that the player cannot see on screen aren’t actually being displayed. Rather than lagging behind, the AI run a series of calculations and perform random events to catch up. This could include rubber-banding (increase or decreasing speed based on their distance from the player) or throwing an item to disrupt the player’s performance.
Avoid Repetition
Smart randomness is best - if there’s a way to randomize something, do it! AI behavior should be rational, but if behavior is too predictable it can make gameplay bland or unrealistic.
Beware the Uncanny Valley
A common mistake is going too far into the uncanny valley by giving a high-fidelity model low-fidelity AI. Finding a balance appropriate for your game’s style is key, as this can negatively impact player perception. For example, if you have a highly realistic human fireman model that teleports from place to place, this destroys the illusion that it’s acting as a human would and makes its behavior uncomfortable or creepy. Realistic graphics require realistic AI.
Be Aware of Its Surroundings
Realistic AI should interact with its environment when it’s appropriate. One trick for this is to have it interact with the things in the world that the player would also interact with. Even small things, like lighting, can have a huge impact on AI behavior. It could notice things that are illuminated or shield its eyes from the sun, while using sneaking behavior in shady spaces. This behavior can also be used to draw attention to areas of interest or demonstrate behavior that can help the player.
Prepare for the Worst
For AI to be most effective, you need to predict as much of the player’s behavior as possible. In Skyrim, for example, it wasn’t anticipated that players would place a bucket on the head of the shopkeeper NPCs to steal their wares without penalty. By trying to predict deviant player behavior, you can create smart AI to accommodate. (It should be noted that the developers opted to keep this bucket exploit in game because it made gameplay even more entertaining.)
Let them Communicate
AI need to interact with other AI - but once again, simplicity is key. There are a few types of base AI behavior when interacting with other AI: flocking, fleeing, and following.
Flocking: A group of AI will select a leader or a focus point and move as close to it as you want them to while remaining equidistant to each other.
Fleeing: AI finds a target to move away from until they reach a point where they are far away from it or out it’s out of sight.
Following: AI follows a target while maintaining a developer-defined distance.
All of these methods help make AI interactions more interesting and impactful.
Help them Find their Path
Finally, you can create realistic AI behavior by using pathfinding. Pathfinding assists the AI in selecting the most optimal route to reach a predetermined target. One trick here is to select a pathfinding method and then adjust it based on variables that are specific to your game. For example, there’s a horror game and an AI monster wants to reach the player. The player has attempted to protect themselves by setting traps and remaining vigilant on one hallway. Rather than move straight through a trap-filled hallway, the monster will recognize and avoid these traps by moving through a hidden corridor and appearing behind the player.
Most pathfinding navigation is based off of a grid. Some popular grid-based pathfinding algorithms include A*, Dijkstra’s algorithm, D*, and any-angle path planning. Most game engines use a navigation mesh or “navmesh” which generates a grid on all navigable terrain. These methods are built into the engine, making them more accessible.
If the AI’s pathfinding behavior isn’t grid-based, it’s likely vision-based. In vision-based pathfinding, the AI decides its course of action after seeing and assessing a target, not before.
Looking for some more interactive examples?
A few of Jack’s favorite game references for AI are Far Cry 2 and Half-Life 2.
“Far Cry 2 is impressive for so many reasons that I recommend you check out this video for a complete summary. Half-Life 2’s AI was impressive because at the time it was made it was a huge advancement in what was thought possible. There are a lot of clever tricks that helped make the AI in Half-Life 2 act properly.”
You can find even more game dev tips by visiting our blog posts on pixel art, sound design, our beginner’s toolkit, and more!
