Tracking how NPCs feel about other characters

I promised to post a thread about my procedural quest generator. This is one of two threads describing it. I haven’t done anything beyond implementing its functionality because I haven’t been able to “find the fun” yet.

It has two parts: a judgment system and a quest generator. The other thread covers the generator.

This thread covers the judgment system, which tracks how NPCs feel about other characters by judging their actions. This determined which NPCs offer quests and the types of quests they offer.

Every NPC has a Faction.

A Faction consists of:

  • Motivations: Such as Security, Justice, and Pleasure, with an importance value assigned to each.
  • Deeds: A record of actions a character has done to another character, ranked by magnitude (murder > teasing) and relevance to motivations.
  • Affinities: How the character feels toward other factions.
  • A set of parent Factions.

So Aragorn has his own faction (motivations, memory of deeds) and also belongs to the Fellowship and Gondor factions. If Aragorn doesn’t have a specific affinity toward Dwarves, he uses his parent factions’ affinity values.

A single action, such as the player reporting his corrupt partner to the police chief, can result in different deed memories and affinity values. The partner loses affinity for the player; the chief gains affinity.

The current implementation only judges actions the player has taken, but it could be expanded to judge other NPCs.

When NPCs meet, if they have positive affinity for each other, they exchange their deed memories (i.e., exchange gossip).

(I won’t claim any of this as my own invention. Full credit goes to all four volumes of AI Game Programming Wisdom and some papers on BDI modeling.)

2 Likes

Interesting, Tony.

I am actually using another system that allows us to assign values and morals to NPCs and track players through their actions. It is probably similar to yours only it doesn’t limit characters to factions, although factions can be included.

I think yours probably would have more practical application as most games made by Unity developers focus on the combat aspects and factions are popular.

I very much like the gossip feature though. How does that work? Do they gossip about their “judgements”?

I’m familiar with this concept at the level of individuals, but I’m a bit confused how deeds get into the higher-level factions’ deed memories.

Let’s say Aragorn observes me chopping up an Ent to build a house… that’s clearly going into his deed memory, and affecting his affinity for me. But when and how does this affect the data in the Fellowship and Gondor factions? If Aragorn slips and breaks his neck before talking to anyone, and I later run into Boromir (also of Gondor), is Boromir’s attitude affected by what Aragorn saw?

Oh, Aragorn just “slips”, eh? :slight_smile:

(I skipped a lot of details in my first post. For example, deed memories expire over time, affinities have certainty values that are the sum of all deeds that have contributed to the affinity, etc. I’ll fill them in if they become relevant to the thread.)

If Boromir never meets Aragorn, he doesn’t know about the Ent-murder, so it doesn’t affect his affinity toward you.

As currently implemented, when Aragorn enters Boromir’s trigger area, they check affinities. Say Boromir has never met Aragorn, so he doesn’t have a direct affinity for Aragorn. But he has two parent factions: Gondor and Stewards. Boromir’s affinity to Gondor is higher than his affinity to Stewards (he’s more loyal to the realm than to his family), so he uses Gondor’s affinity for Aragorn.

If Aragorn and Boromir have positive affinities for each other, they exchange deed memories.

Aragorn tells the deed to Boromir. Boromir judges it against his own motivations and affinity for Ents. He doesn’t care about Ents, so his subjective magnitude for the deed is zero. He doesn’t bother remembering the deed, and it doesn’t affect his affinity toward you.

Now say an Orc sees you. He bumps into Sauron. The chopping is a negative act, but Sauron has a negative affinity for Ents. This results in a positive magnitude for his judgment. He remembers the deed and improves his affinity toward you.

I have a rather klunky method of updating parent factions using broadcasts. Say a town crier hears about the Ent-murder. If he enters a broadcast trigger area, he can update the Gondor faction. All children of the Gondor faction then check their affinities. Barring any extraordinary deed memories, they will remove their own affinity for Aragorn and memory of the deed, leaving it up to the Gondor faction to keep track of this. If they later learn of a deed that affects their affinity toward you, they’ll add the deed memory and their own personal affinity value toward you.

@Teila - I think the description above explains how NPCs “gossip”. They exchange observations (deed memories) and make personal judgments on them.

I used the term “Faction” because it’s familiar. But it needn’t be combat-oriented. Every NPC has its own personal faction. But when it doesn’t have an affinity for another entity, it uses its parent’s faction – that is, the beliefs of its social group.

I’m really interested in how your system differs. Can you describe it?

1 Like

Not sure I can, Tony! lol

It is a purchased package, not something we made. However, it is very flexible. Based on mathematical algorithms and machine learning, it allows us to create networks of values/actions/skills, whatever we like, and define them based on categories, which are probably very much like your faction. We train the computer to recognize when the collection of actions/skills/values/morals places the NPC or player into a certain category. The beauty is how flexible it is and how it can be used for so many things. I have a programmer who is tying it into the game now so we will be testing it soon. I hope it works as well as yours seems to be working.

Yours is more complete though and probably easier to use. I didn’t think about the memory issues so it could be if one is famous, everyone knows they are famous even if they never met them. I am not sure that is a problem since in an oral society, tales of deeds spread quickly. I love your town crier though!

Can you share the name of the package?

Tony, sent a PM. I want to thoroughly test before I talk about it on the forums. If it works, I will crow like a rooster! :slight_smile:

1 Like

The judgment system sounds great, Tony. I’ve been looking for a faction system that allows for individuals to change their responses to situations without entirely losing their place within their group. For example, Romeo and Juliet belong to their family factions, but their allegiances get mixed when the two meet. That’s a common scenario that’s difficult to construct with most faction AI.

2 Likes

Romeo and Juliet is a great example! Implementation-wise, it was just like writing a virtual table for subclasses in polymorphic languages like C#. (The Shape class has Move() and Draw() functions, the Circle subclass overrides the Draw() function, etc.)

1 Like

Has anyone ever thought to put much higher quality AI into NPCs? I don’t think I’ve ever seen NPCs actually doing anything other than walking waypoints, standing still, or occasionally breaking off to fight something before returning to walking/standing.

Limiting the discussion to character-based AI, this is a very active field right now. Shooters are employing all kinds of new techniques to help AI combatants fight smarter. RPG-style NPCs lag behind, but behaving realistically in a social environment is a harder, more ambiguous problem than running-and-gunning. A few fantasy RPGs in development right now are attempting to do more with daily schedules and adapting to change. So, yes, people are putting thought into it.

I imagine the trick is to link behaviors to the “feelings”. We are discussing tracking how NPCs feel about other characters, which basically involves tagging these NPCs based on their in game encounters/actions. The next step would be to actually link behaviors to those tags.

If an NPC greets characters they feel good about in an enthusiastic way, shown by dialogue and/or animations, then he is not just standing still or fighting something. If he sees the other character as an enemy, he will react entirely differently. In my opinion, we need to go behind the simple “attack if NPC hates character” or “ignore if NPC likes character”. While I am under no illusion we can really make NPCs appear completely realistic, we certainly can add to the atmosphere of the game and make it more interesting or entertaining.

2 Likes

Yes! That’s another application of the judgment system. When another character enters their perception trigger area, they check affinity. In addition to sharing deed memories, they bark appropriately based on the affinity values. In the Dialogue System, barks can have cutscene sequences such as animations. Any suggestions for improvement are welcome.

Speaking of feelings, I think a good NPC model might track not only the affinity of each character toward other characters, but also each individual’s emotional state. This could be represented (for example) as a Vector3 in the PAD emotional state model.

So, in the case where the NPC sees another enemy, it’s going to decrease (possibly go negative) on the Pleasure axis, but which way it goes on the Dominance-Submissive axis depends on whether the enemy is considered stronger or weaker. And what happens to the Arousal axis will depend on how intensely the NPC feels about that enemy — he could be a harmless old rival the NPC never liked much, but doesn’t get too excited about. Or he could be the guy who killed a loved one, and our NPC’s arousal goes to the max.

So, rather than scripting responses to situations, maybe we should script the effect of situations on the emotional state, and then responses based on the emotional state.

This could make a noticeable difference. For example, if an NPC is already having a bad day (somebody stole his coin purse, caught his daughter with a boy he doesn’t like, etc.), and then the player goes up and gives an insult, the NPC may just be pushed into high enough Arousal and low enough Pleasure to take a swing at him. But if the same NPC has had a great day — found some coins just lying on the street, wife made him his favorite meal for dinner, etc. — then the same insult would nudge him a little bit in the low-P high-A direction, but not enough to matter, and he just shrugs it off.

Would the player actually notice the difference? I think it depends on the game. If the player just passes through, not spending enough time to get to know anyone, then no, I don’t think it matters. But if it’s a home town sort of situation, where the player is going to keep coming back and seeing the same characters many times, then I think it the player will notice, and it will make a really big difference in seeing the NPCs as virtual people rather than walking quest dispensers.

Okay, I have a practical question.

Joe’s idea sounds very cool and so does linking judgement to actions. But what does this do to the game? I imagine it means lots of little mathematical iterations going on constantly, depending on the complexity of your system and the number of NPCs/Players in the game.

Is there a point where the amount of NPC action/reaction is too much for the game and slows it down to a crawl? If that action is too subtle to be noticed by the majority of the players, is it worth it?

As we work out all our flow charts and examine the possibilities, I get this little niggling in my brain that maybe there is a point where it is just too much.

1 Like

I think it’s more likely that the number of NPCs will slow the client down, before decision making for NPC AI slows the server down. The biggest load on the server is networking and physics. Actual game mechanics isn’t much at all.

I agree. The amount of math we’re talking about here for the AI is trivial compared to the calculations that go on for things like collision detection or animation. And that math doesn’t have to be done every frame, either; updating several times a second would be plenty.

In fact, you could adjust how frequently you run a character’s AI off its Arousal level… if it’s negative, the character’s day-dreaming or drowsy or outright asleep, and you only check its senses and update things every few seconds. When something happens, the character responds sluggishly, as you’d expect. (Though you could also run it immediately if something physically happens to the character, like being attacked.) But if the character’s arousal state is very high, that means he’s excited and engaged, i.e. in fight-or-flight mode. In that case you’d want to run the AI maybe 10 times/sec. But there wouldn’t be very many characters in that state at any given time.

And of all the AI calculations involved here, probably path-finding is the most expensive, and current games are doing that already. The emotional simulation, knowledge-tracking, and affinity stuff is all very quick compared to that.

1 Like

Yay! Thanks guys. It is something that has been bothering me for a while and it is nice to know I don’t have to worry about it anymore. :slight_smile:

Just had a read. Great discussion! See breaking it all down it is not very complicated. Just a matter of tracking more data and taking that data into account when determining the NPC’s reactive behavior. If a servant approaches a guard their status/ranking behavior may make them timid while the same thing makes the guard arrogant and overbearing. But then maybe the servant’s emotional behavior outweighs their status behavior. Maybe they feel oppressed so get very “mouthy” and defiant with the guard. But then again maybe their personal view of this specific guard is very good. This guard has always done right by them so that outweighs even their feeling of oppression.

Thinking about it all and how to make the player actually notice these things I wonder if maybe it would be better to simplify even more? Maybe it would make sense to focus on more specifics as far as how they should come across to the player. Basically profiling the NPCs into stereotypes. This person hates authority. This other person respects it. Another is very afraid. This person is selfish. This other person is generous. I think perhaps players would notice that stuff more.

That is the way I would do it. Put NPCs into categories based on a variety of “ranks” and then attach relative behaviors to those. It might be simpler than doing with emotions and more noticeable.

I am all for simplifying the process. The more complex it gets, the more “oomph” you want for the time you spent doing it. So if it can be done enough to APPEAR to be doing what you want it to do but with less work, it makes sense.

1 Like