Memory Markers

Published August 01, 2015 by Asher Einhorn, posted by BadMemory
Do you see issues with this article? Let us know.
Advertisement

Memory is something that is often overlooked in combat games, more often than not when a character becomes aware of you in a combatative action game, they remain aware until dead. Sometimes they may run a countdown when they lose sight of the player and lapse back into their patrol state if that ends before they find them. Neither of these techniques looks particularly intelligent. The AI either looks unreasonably aware of you, or unrealistically gullible, in that they go about their business after they've lost track of you for a few seconds. A memory marker is a simple trick

">(The UE4 implementation of which can be seen here) that allows you to update and play with the enemy's perception. It is a physical representation of where the enemy 'thinks' the player is. In its simplest form, it has two simple rules:
  • The AI use this marker for searches and targeting instead of the character
  • The marker only updates to the player's position when the player is in view of the AI
this gives you a number of behaviours for free. For example, the AI will look as if you have eluded them when you duck behind cover and they come to look for you there. Just from this minor change you now have a cat-and-mouse behaviour that can lead to some very interesting results. Capture.png I was pleased to see that Naughty Dog also use this technique. In this Last of Us editor screen-grab, you can see their enemy marker (white) has been disconnected from the hiding character It is also very extensible - in more complicated implementations (covered in future video tutorials) a list of these markers is maintained and acted upon. This lets us do things like have the AI notice a pickup when running after the player, and return to get it if they ever lose their target.

So how do we start to go about coding these markers?

In my experience the most important thing when coding this system in various forms is that your memory markers, in code and their references in script, must be nullable. This provides us with a very quick and easy way of wiping these markers when they are no longer needed, or querying the null state to see if the agent has no memory of something - and therefore if we need to create it. The first pass implementation of these markers simply has two rules:
  1. You update the marker for a character to that character's location when its been seen by an enemy.
  2. You make the AI's logic - search routines and so on - act on this marker instead of the character
It's worth mentioning that each AI will need one of these markers for every character on an opposing team, and every object they must keep track of. Because of this, it is useful to populate some kind of array with these markers. Think too, about how you can sort this list by priority. When the AI loses track of a target they can grab the next marker in the list which may be an objective, or a pickup they passed. When the list is empty, they fall back to their patrol state.

Cancel Save
0 Likes 6 Comments

Comments

Eck
Eck

A simple idea that will lead to some cool AI. Very nice sir.

July 31, 2015 06:51 PM
Overman

Great article, and an important feature for AI in my opinion.

For another good reference of this feature I recommend looking into Splinter Cell: Blacklist. They use this as an in-game feature in which you can actually see while playing where the enemy has last spotted you. It definitely makes for more interesting gameplay, especially in a game like Splinter Cell where you can set traps and lure enemies into an ambush. It definitely gives the AI a more intelligent appearance in the game as well.

One of my biggest annoyances when playing games is when the AI can somehow follow you to your exact location despite you being multiple turns ahead of them and them having no sight of you for minutes. This is a perfect way to avoid that problem. I wish more people would incorporate this into their AI.

August 01, 2015 01:18 AM
BadMemory

Ah that is interesting, I personally really like systems where everything is made as clear and obvious as possible so you can make choices based on all that information. There's nothing I find more frustrating than failing in a game, but then realising you really had no way of avoiding the situation.

And on the same subject - I've found that animating every 'moment' in the AI's thought processes gives a huge amount of readability and life to them. So when they are looking for the marker, they say and act a certain way, when they find it and you're not there, there look surprised and double back and so on. None of this is groundbreaking but it really makes them come to life.

August 01, 2015 09:24 AM
Brain

It turns out i'm already using this in my game, but havent ever put a name to it.

This concept of memory markers is a great idea, and does lead for interesting cover-based cat and mouse and trying to get out of the enemies site cone and not make sound so that they just keep looking around where they last saw you.

I do have a couple of questions; firstly, can this be extended by having a list of memory markers for each NPC, so that in the event there is no player in sight around the most recent memory marker he could start back-tracking along the others, looking where it's seen you in past encounters?

Secondly, have you tried combining this with audio cues?

In my game, i am doing so - basically if the NPC hears a sound and cannot see the player, it sets that position as its new 'memory marker' and moves to it. It might be that this sound was purposefully created by the player, e.g. by setting off an explosive spell, or it might even be that the sound was created by an NPC. In the event that the NPC then sees the player on its journey to that sound's location, it engages persuit. If it doesnt find the player there this can be a useful evasion tactic.

Great article, short and to the point. I also wish more game developers were using this trick too.

August 05, 2015 12:05 PM
BadMemory

In answer to your questions braindigitalis, yes and yes. AI's maintaining a list of things they notice and then backtracking when they have nothing else to do it a really nice behaviour for a multiplayer shooter bot. It gives the impression that they are more human (imo anyway).

In fact, in some implementations I assign global markers to spawn locations of weapons and hand them to the higher skill AI's as a low priority task - this gives the impression that the AI's know the maps, and that they are sweeping it for pickups.

I like your thinking on the audio queues. We call those 'events' and derive them from a common base struct so they can be processed by the behaviour trees in a generic way - whether it's the player popping up, an explosion in the distance or a player who suddenly cloaks. For the latter we override the default behaviour to trigger unique actions.

I'm a big fan of making these kind of components generic, because it lets you add more and more without having to really do any additional work.

August 05, 2015 12:12 PM
Brain

Thanks for the response!

It would also be clever if when two AI pawns meet in the map, they pause for a few seconds, animation showing they're talking and or gesturing to each other. At this point they exchange known lists of memory markers.

Basically they talk to each other and share your location so they can gang up on you... :)

August 05, 2015 04:27 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!

Inspired by the 'Simplest trick I know' series of GDC talks, I've begun to document all the small code and design tips and tricks I've picked up on my way through the industry

Advertisement

Other Tutorials by BadMemory

Advertisement