For AI agents: the complete documentation index is available at /npc-mentality/en/llms.txt, the full documentation bundle is available at /npc-mentality/en/llms-full.txt, and this page is available as Markdown at /npc-mentality/en/usage/emotion.md.

Emotion-Based Animation System

One line sets movement speed, animator triggers, and blink rate automatically.

Overview

Before:
  anim.Play("Idle");

NPC Mentality:
  emotion.Set(Emotion.Angry);
  → Auto: walk speed increase / head shake / expression change / blink decrease

Component

EmotionController — MonoBehaviour.

FieldTypeDescription
AnimatorAnimatorNPC animator
AgentNavMeshAgentMovement speed control (optional)
CurrentEmotionEmotionTypeCurrent emotion (read-only)

EmotionType Enum

public enum EmotionType
{
    Neutral,
    Happy,
    Angry,
    Sad,
    Afraid,
    Surprised,
    Disgusted
}

API

Set

void Set(EmotionType emotion)

Sets the emotion and applies effects immediately.

emotion.Set(EmotionType.Angry);
emotion.Set(EmotionType.Happy);
emotion.Set(EmotionType.Neutral); // Reset

Effects by Emotion

EmotionNavMesh SpeedAnimator TriggerBlinkRate
Neutral×1.0 (default)"Idle"1.0
Happy×1.0"Happy"1.0
Angry×1.5"Angry"0.3 (decreased)
Sad×0.7"Sad"0.8
Afraid×1.3"Afraid"1.5 (increased)

Animator Parameters: BlinkRate (Float), and a Trigger parameter for each emotion.


Animator Setup

Parameters:
  BlinkRate   [Float]    — Connect to blink speed Blend Tree
  Idle        [Trigger]
  Happy       [Trigger]
  Angry       [Trigger]
  Sad         [Trigger]
  Afraid      [Trigger]

Example

using NpcMentality;

public class NPCReaction : MonoBehaviour
{
    private NPCMemory _memory;
    private EmotionController _emotion;

    private void Awake()
    {
        _memory  = GetComponent<NPCMemory>();
        _emotion = GetComponent<EmotionController>();
    }

    public void OnTalkWithPlayer()
    {
        float attitude = _memory.GetAttitude();

        if (attitude < -8f)
            _emotion.Set(EmotionType.Angry);
        else if (attitude < -2f)
            _emotion.Set(EmotionType.Disgusted);
        else if (attitude > 8f)
            _emotion.Set(EmotionType.Happy);
        else
            _emotion.Set(EmotionType.Neutral);
    }

    public void OnCombatStart() => _emotion.Set(EmotionType.Afraid);
    public void OnCombatEnd()   => _emotion.Set(EmotionType.Neutral);
}