In this lesson, you will learn how to manipulate the mathematical shape of response curves to transform a single AI logic system into distinct, recognizable character archetypes.
The Power of Curve Mapping
While we’ve previously established how to calculate utility scores, the true "personality" of an NPC lives in how they react to those scores. If your UtilitySelector evaluates a Health variable, a linear response (e.g., utility = 1 - healthPercentage) makes every NPC behave identically. By passing that raw input through a non-linear function—a "Response Curve"—we can force agents to prioritize specific needs based on their unique temperament.
Tuning for Archetypes
Think of the curve as a filter between raw data and action selection. We can use AnimationCurve assets in Unity to visually define these biases:
- Aggressive Agents: Use a curve that stays at a high utility value even when a threat is distant, but spikes sharply when the threat is close. They ignore danger until it is imminent.
- Cautious Agents: Use an exponential curve. Their utility for "Retreat" starts climbing rapidly as soon as they take even minor damage, prioritizing survival over objectives.
- Erratic Agents: Use a curve with multiple inflection points or a high-frequency noise modifier. This causes the agent to oscillate between different actions, making their decision-making process feel unpredictable and "twitchy."
Example Implementation
In your UtilityEvaluator, instead of returning the raw value, apply the curve:
public class PersonalityEvaluator : MonoBehaviour
{
public AnimationCurve responseCurve; // Defined in the Inspector
public float Evaluate(float rawInput)
{
// rawInput is typically normalized (0 to 1)
// The curve transforms this input into a personality-specific output
return responseCurve.Evaluate(rawInput);
}
}
By tweaking the keys of the AnimationCurve in the inspector, you can turn a "Brave" agent into a "Cowardly" one without writing a single new line of logic or adding more states to your planner. You are essentially shifting the "decision threshold" so that the agent favors specific outcomes earlier or later than their peers.
Key Takeaway: Personality is not defined by the AI's logic, but by the shape of the curves that determine how much importance the AI assigns to specific world states.