Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Tracking how NPCs feel about other characters

Discussion in 'Game Design' started by TonyLi, Nov 18, 2014.

  1. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    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.)
     
    Last edited: Nov 18, 2014
    _met44 and Whippets like this.
  2. Teila

    Teila

    Joined:
    Jan 13, 2013
    Posts:
    6,927
    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"?
     
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,840
    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?
     
  4. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    Oh, Aragorn just "slips", eh? :)

    (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?
     
    JoeStrout likes this.
  5. Teila

    Teila

    Joined:
    Jan 13, 2013
    Posts:
    6,927
    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!
     
  6. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    Can you share the name of the package?
     
  7. Teila

    Teila

    Joined:
    Jan 13, 2013
    Posts:
    6,927
    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! :)
     
    TonyLi likes this.
  8. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,623
    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.
     
    TonyLi and Teila like this.
  9. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    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.)
     
    Teila likes this.
  10. Whippets

    Whippets

    Joined:
    Feb 28, 2013
    Posts:
    1,775
    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.
     
  11. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    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.
     
  12. Teila

    Teila

    Joined:
    Jan 13, 2013
    Posts:
    6,927
    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.
     
    hopeful and TonyLi like this.
  13. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    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.
     
  14. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,840
    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.
     
  15. Teila

    Teila

    Joined:
    Jan 13, 2013
    Posts:
    6,927
    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.
     
    RJ-MacReady likes this.
  16. Whippets

    Whippets

    Joined:
    Feb 28, 2013
    Posts:
    1,775
    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.
     
  17. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,840
    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.
     
    GregMeach likes this.
  18. Teila

    Teila

    Joined:
    Jan 13, 2013
    Posts:
    6,927
    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. :)
     
  19. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    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.
     
  20. Teila

    Teila

    Joined:
    Jan 13, 2013
    Posts:
    6,927
    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.
     
    GarBenjamin likes this.
  21. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,840
    True, but that path leads to static, two-dimensional characters. Fine for NPCs the player isn't going to see much, but I worry that for characters the player really gets to know, the simple stereotyping would become painfully apparent, versus characters that actually adapt and change based on what happens to them.

    On the other hand, code should always be made as simple as possible (though no simpler). And there is a constant tension between characters getting more autonomous, and designers wanting to have control. In other words, the more AI you put into your NPCs, the less you can be certain what they're going to do, which could be a problem for a strongly story-driven RPG in particular.
     
  22. Teila

    Teila

    Joined:
    Jan 13, 2013
    Posts:
    6,927
    I believe it can be done without it being 2 dimensional but won't know until I try it. :)

    My concerns with emotions is that they may not always suit the setting. Emotions would have to be influenced by what is going on in the game, which is an entire new level of influence. It is an excellent idea and I would love to see it done though. :)
     
  23. RJ-MacReady

    RJ-MacReady

    Joined:
    Jun 14, 2013
    Posts:
    1,718
    The boys over at Team Meat are tackling character emotion through, of all things, cat behavior. The game is called Mew-Genics. The cats learn, gaining fears and aversions, preferences as well. The game is currently on hold while they release a sequel to Super Meat Boy.

    ~

    People try really hard to get games to be fun with known formulas, how would you make sure the game was fun when you have no control over the play experience?
     
  24. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    That's the old debate over hand-authored versus sandbox. There's something appealing (and scary for the designer) about the idea of seeing an NPC become happy because of something the player has actually done to change the game world, versus becoming happy because the writer has dictated ahead of time, "at this point, the NPC will act happy because I'm the writer and that's what I decree." Hence the judgment and affinity system.
     
    JoeStrout likes this.
  25. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,840
    Indeed — a topic worthy of its own thread, I'd say.
     
    TonyLi likes this.
  26. RJ-MacReady

    RJ-MacReady

    Joined:
    Jun 14, 2013
    Posts:
    1,718
    A block in minecraft, the most sand-boxy game I've ever played, behaves the same at all times. The freedom to change parts of the world is hardly comparable to complete randomness without aim. What if my companions decide to try to kill me one day? What if the shop keepers all quit selling potions? What if the villain gives up on evil because some character convinced him to?

    Furthermore, as long as you're fulfilling fantasies of being God in this way, how will you answer the question of free will? If characters can only behave according to the programming you created for them, anything that happens is something you forced to happen on the player. Thus, it's still scripted. :/
     
    TonyLi likes this.
  27. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,623
    Speaking of NPC combat AI and affinity barks ... what I'm hoping to eventually use in that regard is a system where there are degrees of communication within enemy groups that can differ from group to group.

    I guess we start off with a more "amoebic" sort of AI, which would be the common AI in games. In this situation, enemies only aggro when attacked.

    A slightly higher level of AI, which could be for an unorganized, anarchic, or bestial faction, would be where they react if they perceive something. So they respond to aggro on them and also if they see or hear aggro occurring nearby. Crowds of bystanders, for instance, might flee the scene of a violent conflict if they can see or hear it.

    Upgrading from that, I'd like to have the ability to give minions (or leaders) that are capable of speech the ability to shout a message (or command) that would influence the actions of others within the shout radius.

    If an enemy group has radio or telepathy, I'd like for them to be able to transmit to the local group, but not necessarily to the entire faction (most of whom may be outside the scope of the current quest).

    To top it off, I'd like to have a "hive mind" option, where maybe the entire faction becomes instantly aware of the message or command.

    If we're thinking of affinities, the judgment system seems like it could be a good step in this direction. If a player walks into a large building or encampment of some sort and gets into a conflict with an individual, depending on the nature of the enemy and circumstances it could be that it remains a small issue, or perhaps nearby reinforcements might come in, or perhaps the entire faction now identifies the player's character as an enemy.
     
  28. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    A group has revived the associated procedural quest generation thread and mentioned this thread, which was an offshoot.

    The discussion in this thread resulted in the product Love/Hate. If you'd like to discuss this topic further, please join us on the Love/Hate thread. :)
     
  29. El Maxo

    El Maxo

    Joined:
    May 23, 2013
    Posts:
    177
    Sorry if I am reading this wrong (struggling in some parts to understand). But you have Factions, Deeds, Affiliates and motivation. Now as I am reading it I believe you have missed 2 things that are very valuable in this type of environments, (thought they may have been included in your ones). These are backstory and traits, backstory will be very important, more so in a older set time period, a present wouldn't know how to properly address a lord,someones dad could of been killed by a ork, so they hate orks, it adds depth and history. Another thing is traits, crusader kings does this well, other than minor perks or deperks(?) it has a massive influence on other characters relationship, if someone is pious the are not going to like a cynical person, but they would love a crusader. I believe if you add these, you can add more depth into your system, although you will only gain this depth if they act with backstory and traits that you give them.
     
  30. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    Love/Hate already has traits. Good points about perks and backstories. I put hooks into Love/Hate so you can easily add things like this as appropriate for your project. Much of it is automatic and already inherent in the system. If a lord sees that has dad was killed by an ork, or hears it from family, he'll automatically hate orks.
     
  31. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,623
    Perks? Not sure what that means here.

    Quirks?
     
  32. sicga123

    sicga123

    Joined:
    Jan 26, 2011
    Posts:
    782
    Possibly you are unfamiliar with the way Royal families and noble households work which is the reason everyone hates to be under a monarch. If Henry VIII had your father killed for treason it was generally accepted that one just inherited the title and got on with sucking up to the fat geezer on the throne because he had control of all the guys with the sharp pointy objects. Besides powerless people may hate and despise others but will only do something about it when they can get away with it. A guy might hate orcs but if he comes across a raiding party of 50 orcs and he's on his own I assume the system has overrides so a character wouldn't run out and get killed becuase of his 'hatred' of orcs.
     
  33. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    Good points, and I think that's where Love/Hate shines. Love/Hate serves a single, very specific purpose: it handles how your characters feel. What your characters do, on the other hand, is up to you. There are code hooks and integration packages for PlayMaker and Behavior Designer. Your behavior tree could gauge the number of orcs versus how strongly the character hates them and decide whether to attack or flee. It's entirely possible that if he hates them enough, he could fly into a suicidal rage. But, again, that's up to you. Love/Hate is designed to provide emotional information to your "rational" AI logic to help it make interesting decisions.

    In the royal court scenario, similarly, the son might pay surface obeisance to the king but work against him in secret.
     
    Last edited: May 16, 2015
    Kiwasi, hopeful and Teila like this.
  34. sicga123

    sicga123

    Joined:
    Jan 26, 2011
    Posts:
    782
    Love/hate is a good package, I already have it. The orc statement was a bit of nonsense really. Just looking at the demo convinced me it had great possibilities for emergent gameplay and adaptive A I and was worth investing a bit in it to see how it gets developed.It's one of those assets that once one starts messing about with it all sorts of new ideas suddenly start flashing.
     
    TonyLi likes this.