Emotion‑Driven AI System in Unity (Fear, Aggression, Morale, Stress)

High‑Complexity AI Sensory System in Unity
High‑Complexity AI Sensory System in Unity (Sight, Hearing, Threat & Interest)
September 4, 2026
Leader Auras for AI Morale
Leader Auras for AI Morale & Emotional Control in Unity
September 6, 2026
High‑Complexity AI Sensory System in Unity
High‑Complexity AI Sensory System in Unity (Sight, Hearing, Threat & Interest)
September 4, 2026
Leader Auras for AI Morale
Leader Auras for AI Morale & Emotional Control in Unity
September 6, 2026

Emotion‑Driven AI System in Unity (Fear, Aggression, Morale, Stress)

Emotion-driven AI enables NPCs to behave more like living beings rather than simple state machines.
By simulating fear, aggression, morale, confidence, and stress over time, we can create deeply reactive and emergent gameplay—perfect for RPG, Survival, Stealth, Tactical, and Horror games.


1. Why Emotion‑Driven AI?

Traditional AI reacts only to current stimuli.
Emotion-driven AI reacts to:

  • Current situation
  • Past experiences
  • Internal state (stress, fatigue, morale)
  • Group dynamics
  • Character personality traits

This system forms the emotional brain of an NPC.


2. Emotional Model Architecture

The system is composed of:

  1. Core Emotional Stats (fear, aggression, morale, stress)
  2. Personality Modifiers (bravery, temper, discipline)
  3. Emotion Decay System (return to baseline)
  4. Event-to-Emotion Mapping (damage, allies dying, victory)
  5. Behavior Output System (fight, flee, panic, surrender, frenzy)

Each NPC keeps its own emotional brain.


3. Emotional State Class

[System.Serializable]
public class EmotionState
{
    public float fear = 0f;
    public float aggression = 0f;
    public float morale = 1f;
    public float stress = 0f;

    public float bravery = 0.5f;    // personality trait
    public float temper = 0.5f;     // personality trait
    public float discipline = 0.5f; // personality trait

    public float lastUpdateTime;
}

4. Emotion Update & Decay

Emotion values naturally decay to their baseline.

public class EmotionSystem : MonoBehaviour
{
    public EmotionState state = new EmotionState();

    void Update()
    {
        float dt = Time.deltaTime;

        // Emotional decay
        state.fear = Mathf.MoveTowards(state.fear, 0f, dt * 0.3f);
        state.aggression = Mathf.MoveTowards(state.aggression, 0f, dt * 0.2f);
        state.stress = Mathf.MoveTowards(state.stress, 0f, dt * 0.15f);

        // Morale regenerates slower
        state.morale = Mathf.MoveTowards(state.morale, 1f, dt * 0.05f);
    }
}

5. Emotional Reactions to Events

This is where NPCs start “feeling”.

public void OnDamage(float amount)
{
    state.fear += amount * (1f - state.bravery);
    state.stress += amount * 0.5f;
    state.aggression += amount * state.temper;
    state.morale -= amount * 0.4f;
}

public void OnSeeAllyDie()
{
    state.fear += 0.5f * (1f - state.bravery);
    state.morale -= 0.4f * (1f + state.discipline);
    state.stress += 0.3f;
}

public void OnSuccessfulHit()
{
    state.aggression += 0.2f;
    state.morale += 0.1f * state.temper;
}

public void OnGroupNearby(int allies)
{
    state.fear -= allies * 0.1f;
    state.morale += allies * 0.05f;
}

Every input shifts emotional values.


6. Emotional Thresholds → Behavior Outputs

Different behaviors trigger depending on emotional balance:

High Fear → Flee / Panic
High Aggression → Charge Attack / Rage
Low Morale → Surrender / Call for Help
High Stress → Defensive / Inaccurate actions
Balanced → Normal Combat
public enum AIEmotionalState
{
    Normal,
    Aggressive,
    Fearful,
    Panicking,
    Defensive,
    Surrendering
}

public AIEmotionalState Evaluate()
{
    if (state.fear > 0.7f && state.morale < 0.3f)
        return AIEmotionalState.Panicking;

    if (state.fear > 0.6f)
        return AIEmotionalState.Fearful;

    if (state.aggression > 0.6f && state.morale > 0.5f)
        return AIEmotionalState.Aggressive;

    if (state.morale < 0.2f)
        return AIEmotionalState.Surrendering;

    if (state.stress > 0.6f)
        return AIEmotionalState.Defensive;

    return AIEmotionalState.Normal;
}

7. Behavior Integration (BT / FSM)

Emotion state feeds directly into Behavior Tree or State Machine.

Example: Finite State Machine

Normal → Engage Enemy
Aggressive → Charge / Attack / Taunt
Fearful → Back away / Seek allies
Panicking → Flee blindly / Drop weapon
Defensive → Block more / Retreat carefully
Surrendering → Drop to knees / Hands up

Charge Attack Example:

if (currentEmotion == AIEmotionalState.Aggressive)
{
    agent.speed = runSpeed * 1.2f;
    DoChargeAttack();
}

Panic Example:

if (currentEmotion == AIEmotionalState.Panicking)
{
    agent.speed = runSpeed * 1.4f;
    RunInRandomDirection();
}

8. Personality System (Character-Based Variation)

Two NPCs receiving the same stimulus react differently because of personality traits:

  • Brave soldier → low fear, high discipline
  • Hot‑headed thug → high aggression, low discipline
  • Cowardly bandit → high fear, low morale
public void ApplyPersonalityPreset(string type)
{
    switch (type)
    {
        case "soldier":
            state.bravery = 0.8f;
            state.temper = 0.4f;
            state.discipline = 0.9f;
            break;

        case "berserker":
            state.bravery = 0.6f;
            state.temper = 0.9f;
            state.discipline = 0.3f;
            break;

        case "coward":
            state.bravery = 0.2f;
            state.temper = 0.3f;
            state.discipline = 0.2f;
            break;
    }
}

9. Emotional Group Dynamics

NPCs react to allies:

  • More allies → morale up
  • Allies fleeing → fear up
  • Leader dying → group panic
public void OnAllyFled()
{
    state.fear += 0.3f;
    state.morale -= 0.2f;
    state.stress += 0.2f;
}

Group behavior emerges automatically.


10. Advanced Features (AAA-Level)

  • Emotion Heatmaps to track dangerous areas
  • Long‑term emotional memory (NPC remembers you scared them earlier)
  • Panic contagion (fear spreads among NPCs)
  • Voice-line emotional modulation (“Don’t shoot! I’m surrendering!”)
  • Morale-based accuracy drop
  • Stress-based animation overrides (shaky aim, trembling)
  • Cinematic death reactions triggered by fear spikes

11. Summary

Emotion-driven AI transforms enemy encounters into organic, reactive, and deeply engaging experiences.
By modeling fear, aggression, morale, and stress—and blending them with personality and group dynamics—you create AI that:

  • Feels alive
  • Behaves unpredictably but logically
  • Produces emergent gameplay
  • Supports stealth, tactical, and RPG design
  • Is far more fun to fight or observe

This emotional brain fits perfectly with Behavior Trees, State Machines, and High-Complexity Sensory Systems.

Leave a Reply

Your email address will not be published. Required fields are marked *


Skip to toolbar