Course contentsShow
← Unity Game Development
Lesson 562 of 8288. Artificial IntelligenceFree lesson

Weighting Factors for Multi-Criteria Decision Analysis

Apply importance multipliers to different utility inputs to prioritize specific goals and influence the overall character personality during the decision process.

In this lesson, you will learn how to apply importance multipliers to various utility inputs to sculpt NPC personality and prioritize specific behavioral goals.

Beyond Raw Utility

Previously, we normalized inputs—like Health, Ammo, and DistanceToTarget—to a 0.0 to 1.0 range. However, treating all these inputs as equally important is rarely realistic. A "brave" NPC might value DamagePotential much higher than SelfPreservation, while a "cowardly" NPC would do the exact opposite. We achieve this by introducing Weighting Factors.

A weighting factor is a multiplier applied to a normalized utility score. By increasing the weight of a specific input, you amplify its "voice" in the NPC's final decision-making process.

Implementing Weighted Decisions

Consider an NPC deciding whether to engage an enemy. We define a weight for each criteria to reflect its personality:

public class DecisionWeighting : MonoBehaviour
{
    // Personality weights
    public float healthWeight = 1.5f;   // Cowardly: high weight on health
    public float ammoWeight = 0.8f;    // Less concerned with ammo
    public float enemyProximityWeight = 1.2f;

    public float CalculateDecisionScore(float health, float ammo, float dist)
    {
        // Inputs are already normalized (0-1)
        float score = (health * healthWeight) + 
                      (ammo * ammoWeight) + 
                      (dist * enemyProximityWeight);
                      
        return score;
    }
}

Influencing Personality

By adjusting these weights at runtime, you can create nuanced AI behaviors. If an NPC is under "Panic" status, you might boost the healthWeight significantly, forcing the NPC to abandon its objective and retreat. Because these weights act as coefficients in your Utility Score formula, they directly dictate which action "wins" during the selection phase.

When you combine normalized data with these weights, you aren't just calculating the most logical move; you are calculating the most in-character move. This allows a single decision-making script to support vastly different archetypes simply by swapping a configuration of floating-point multipliers.

Key Takeaway: Weighting factors act as personality modifiers that scale individual input priorities, allowing you to influence NPC decision-making without changing the underlying logical framework.