Monday 9 November 2015

NPC Emotions

emotion masks This is part of a series about potential future developments in IF, particularly in the area of believable characters. One way to make NPCs more human is to model their emotions. This area has been explored quite a bit in the context of Artificial Intelligence.

A model of NPC emotions is particularly useful in the area of autonomous NPCs, where interactions can happen that are difficult to predict. Using general rules rather than scripting reactions to every possible combination of events is a good way to manage this kind of complexity.

Categorising Emotions

“I’m Joy, this is Sadness, that’s Anger, this is Disgust, and that’s Fear. We’re Riley’s emotions.”

Inside Out movie trailer

Inside Out characters   Plutchik wheel of emotions

There have been quite a few attempts at classifying emotions into groups, or reducing them to a set of basic emotions. The first step in modelling NPC emotions is deciding which ones to include.

The radial image above is known as Plutchik’s wheel of emotions (click to view in a new window). There is a colour for each emotion, with lightness representing intensity. The main emotions are joy, trust, fear, surprise, sadness, disgust, anger and anticipation. Additional emotions are a combination of adjacent ones: love equals joy plus trust, and so on. This model is is used in an experimental Inform 7 extension by Brian Jack.

Plutchik describes the background to his model in an American Scientist article (PDF, 2.5M). Here is a clearer image of Figure 5:

Plutchik figure 5

A commonly used model of emotions in the context of AI is the OCC model, named after its creators Ortony, Clore and Collins. It was originally proposed in The Cognitive Structure of Emotions (1988). An excerpt is available here (PDF, 5M). One attractive feature is that it is designed for computation: each emotion has a definite cause, and its effects are described numerically.

The OCC model includes twenty two emotions, in opposite pairs. They are:

Emotion (opposite)FocusAttitudeRegarding
Joy (distress)Own fortunes(Dis)pleased abouta desirable event happening to self
Happy for (pity)Fortunes of others(Dis)pleased abouta desirable event happening to another
Gloating (resentment)Fortunes of others(Dis)pleased aboutan undesirable event happening to another
Hope (fear)Potential event(Dis)pleased aboutthe prospect of a desirable event
Satisfaction (fears confirmed)Actual event(Dis)pleased abouta desirable event coming to pass
Relief (disappointment)Actual event(Dis)pleased aboutan undesirable event not coming to pass
Pride (shame)Evaluation of self(Dis)approving ofown praiseworthy action
Gratification (remorse)Evaluation of self(Dis)approving of & pleased aboutown praiseworthy action & desirable consequences
Admiration (reproach)Evaluation of others(Dis)approving ofanother’s praiseworthy action
Gratitude (anger)Evaluation of others(Dis)approving of & pleased aboutanother’s praiseworthy action & desirable consequences
Love (hate)Attraction(Dis)likingan appealing object

One implementation of the OCC model is described in GAMYGALA: An Emotion Engine For Games (PDF, 2.4M). This article appeared in the Journal of IEEE Transactions on Affective Computing (“affect” meaning feeling or emotion).

Personality, Mood and Emotions

It can be helpful to distinguish between short term emotions (e.g. being happy about an event), longer term moods (feeling cheerful) and an NPC’s overall personality (having a positive disposition).

In the Gamasutra article Artificial Emotion: Simulating Mood and Personality, Ian Wilson suggests that the most intense of these three at any particular time is the one that wins out, as shown in the diagram below.

One complication the article doesn’t address is what happens when there are multiple (potentially conflicting) emotions, such as an event that provokes fear and anger at the same time.

Personality can have a strong influence on emotions; for example, an NPC who is open to experience might be excited at the prospect of adventure, while an NPC who is particularly neurotic might react with trepidation. We will look at personality in a future post.

Indicating Emotional State

Once NPCs have been endowed with emotions, these need to be communicated clearly to the player – which is potentially troublesome, because it could be distracting to try and indicate a character’s complete emotional state at all times. The focus should probably be on the most intense ones, as well as significant changes such as a decrease in a strong emotion. It should also be guided by the NPC’s role in the story.

Emily Short was involved in a project called Versu, a storytelling system which we will look at in a later post. She writes in her blog:

“Yes, it is useful to have character reactions and mutual evaluations modelled numerically, to have a sense of accumulation and of actions having large and small effects.
...
“But the numbers and thresholds by themselves are not enough to produce satisfying drama or a sense of agency. You also need to communicate to the player what the current status is, and when the characters are close to one of those thresholds, and which if any actions are likely to have some effect. “George is .952 angry” is not story content, and “George is very angry” is only somewhat better. You really want, if possible, “George is so angry that one more rude remark will push him over the edge.” That puts stakes on the player’s activities and gives them a context for their own character’s actions.

“It may feel as though the player ought to just be able to sense how the interaction is going, that it gives too much away to say “George is nearly ready to punch you”; but in a system with so many moving parts, being explicit is preferable to being vague if we want the player to have any hope of acting with intention.”

However, a character’s emotions might not be intended to provoke a response from the player. A companion NPC might simply be frightened, elated, filled with anticipation or compassion as a realistic reaction to the current situation, in which case a more subtle description may be appropriate, such as changes in body language. Dialog is another way to indicate emotion: “There’s no way out – we’re doomed!” comes across differently to, “I wonder how we’ll get out of here.”

The game’s conversation system could need to handle discussions about emotion, such as asking “What’s wrong?” of an NPC who is upset. This requires emotions to be represented as more than just numbers; NPCs would need to be aware of the history that led up to them. But it may be enough to just store the single main cause of an emotion: “Hello. My name is Inigo Montoya. You killed my father. Prepare to die.”

Uses For Emotions

What kinds of things could an advanced IF system do with NPC emotions? Let’s take a closer look at the way emotion works in real life.

1. Interpretation of events

Emotions are cognitive: the result of a mental process. It is not the event itself that causes an emotion, but our interpretation of it. If a slap in the face is seen as a sign of affection in the cultural context, then it might make a person feel affirmed and included (as well as stinging a little). In another context the same event might leave someone feeling shamed or angry.

A particular event might be seen as very significant to an NPC, in a positive or negative way. For example, a child who looks up to the PC might feel treated like an adult by being given an important message to deliver, or dejected and sad if the PC doesn’t acknowledge him.

Since emotions are to do with our interpretation of events, there is plenty of potential for misunderstanding. Based on the PC’s words and actions, an NPC might assume he is upset with her or challenging her or pursuing her romantically, when that is not the case at all. To avoid frustration for the player, this kind of misinterpretation should probably be minimised, but it could be an interesting plot point.

Past events can also be re-interpreted in the light of new information, causing the originally felt emotions to be revised – perhaps even stronger in the other direction to compensate: “I thought you had betrayed me, but I so misjudged you ... can you ever forgive me?”

2. Feelings and emotions

Emotions can be felt (they involve physical sensations), but not all feelings are emotions. People can feel tired, cold, hungry, thirsty and be in physical pain, which are physiological rather than mental. But they do have an effect on emotional state: someone who experienced all of these symptoms at once might not be too happy.

It may not be desirable to simulate things like hunger and thirst in detail (simulation can be at the expense of fun), but if an NPC is has gone days without food or has a broken leg, it should certainly influence his dialog and behaviour.

3. Learning

Emotions help people learn about the world, establishing and reinforcing beliefs. In the movie Inside Out, the character of Disgust causes Riley to spit out her broccoli, telling the others: “Well, I just saved our lives.”

An NPC who feels positive emotions when interacting with the PC might grow in trust and friendship; someone who keeps having unpleasant experiences with the PC might become cold and guarded, or even his enemy.

4. Communication

Although emotions are revealed by words and behaviour, they are mainly communicated through body language. Many emotions can be identified through facial expression alone. There is room for misinterpretation, but it is usually clear when someone is trembling with fear, fidgeting impatiently or sighing with relief.

An NPC might unintentionally give away his true feelings through body language: a villain may rub his hands with glee when the PC seeks shelter from a storm in his castle; a collector might gasp upon seeing a rare item; someone who is not used to being deceitful may cough before lying.

Showing emotions can also be done deliberately. For example, someone learns as a child that throwing tantrums helps them get their way, so they continue the practice into adulthood. Emotions can also be faked: a murderer might act fearfully in order to avoid suspicion.

5. Stirring up emotions

As well as actual events, emotions can be provoked by imagination, memory or empathy towards others. A story or song can arouse all kinds of feelings, from compassion to amazement. Recalling a fond or painful memory can bring powerful emotions to the surface.

An NPC might have a sore spot that provokes a strong reaction when it is brought up. On the other hand, it may inspire and encourage an NPC to be reminded of certain things, such as their past bravery or how much is at stake.

Emotive arguments can be used to persuade or manipulate people. For example, guilt: “After all I’ve done for you ...” A skillful orator might stir up a crowd to rebel against their ruler. It is possible to appeal to someone’s compassion, feed their pride or play upon their fears. However, someone who discovers they are being manipulated might react quite badly when they see it.

6. Reason and emotion

Emotions can contradict rational thinking. The rope bridge across the chasm may be perfectly secure, but your stomach lurches and you feel suddenly dizzy when you glance downwards. An addict knows his drug is harmful, but the pull is just too strong. An enraged husband says and does things he later regrets, because the emotion temporarily consumed him.

NPCs who are feeling a particularly intense emotion might make unwise decisions. This can apply to positive emotions as well as negative ones; for example, in the exhilaration of recent victory he might become overconfident. The PC could try and provoke such emotions to cause an enemy to make a mistake.

Some people are led by their emotions more than others. This isn’t a bad thing in itself; passionate characters who feel everything strongly can be quite memorable in a story. However, such characters may clash with other NPCs who place a higher value on reason than emotion.

People can still choose how to react in spite of strong emotions. Someone might respond kindly to an insult rather than retaliating in anger, or act compassionately to a person who smells revolting instead of avoiding them. Temptation can be rejected or given in to. NPCs might have a conflict between what they feel and what they know is right, or may need to temporarily put aside their feelings to achieve a certain goal.

Paradoxically enough, emotions also support rational decision making. In The Rationality of Emotion, Ronald de Sousa writes (paraphrase): “The role of emotion is to compensate for the insufficiency of reason alone. For a limited amount of time, an emotion limits the range of information that the organism will take into account, out of a potentially infinite amount. Emotions direct our attention to what is most pertinent to the current situation.”

This concept could potentially be applied to planning algorithms to help limit the search space, imitating de Sousa’s model of real life organisms.

7. Hiding and suppressing emotions

Not everyone is comfortable with showing their emotions. In certain cultures it is socially inappropriate to display too much affection; there can be role based taboos such as boys not crying, or situational taboos such as not laughing during a funeral.

NPCs could have a set of rules that restrict the display of emotions in certain contexts. Encountering another character (such as the PC) who violates their rules could be quite confronting. They might feel offended and try to correct their behaviour; or it might be refreshing to be around someone who seems so uninhibited.

Certain people can find a particular emotion so difficult to deal with that they suppress it completely, becoming out of touch with how they really feel. For example, a painful experience such as losing a loved one might feel so overwhelming that the person attempts to shut down that part of herself, in order to avoid going through the same thing ever again. Unfortunately suppressed emotions don’t disappear, they just grow stronger (affecting the person’s behaviour in ways they don’t really understand, because it is an area that is too scary to look at).

It could be a turning point in the story when an NPC honestly faces what is going on inside and takes the risk of becoming vulnerable again. Such stories can be very resonant with readers, since everyone is familiar with issues of facing difficult things and choosing between safety and vulnerability.

The process of inner change can be quite complex, however. In the web series Creating Stunning Character Arcs, K.M. Weiland discusses The lie your character believes and the narrative sequence of perceiving and overcoming that lie over the course of the story. A model involving character change over time probably has more to do with drama management than NPC emotions, which is a topic for a future post.

2 comments:

  1. This is interesting stuff. I doubt I'll feel the need to model emotion to this level of depth in the game I'm working on, but it's useful modeling it in my own head, at least.

    By the way, you may be interested to know that people are talking about your blog and this post. This has been recommended to me twice as being relevant to my current work. Thanks for writing it up!

    ReplyDelete
    Replies
    1. Thanks Ashton. I guess my approach to modelling a human being is to start by looking at the broadest kind of model first, then narrow it down later.

      Now I'm really curious: what kind of thing are you working on that this applies to?

      Delete