Modelling character traits can be tricky: an example problem has been presented by Jon Ingold in this GDC talk. I discuss the problem below and present a sample model that solves it. I provide an implementation in a C# class.
For character trait one may think of say the character happiness, or a relationship-with-X trait.
The problem is presented from minute 36 of the talk: the first idea that comes to mind in modelling a character trait is by using a number. Greater the number, better the state of the trait. This doesn’t work very well.
From Jon Ingold GDC talk.
Then Ingold quickly jumps to a proposed solution, which consists in tracking two numbers, positive and negative experiences:
From Jon Ingold GDC talk.
Apart from the fact that changes are modelled more appropriately using two variables, what was exactly the problem with using one number?
Here is how I understood the problem: suppose you want to model the happiness of a character in a gameplay. You say that the variable HappinessLevel determines HappinessState according to these values:
HappinessLevel >= 5 = VERY_HAPPY
0 < HappinessLevel < 5 = HAPPY
-5 < HappinessLevel <= 0 = SAD
HappinessLevel <= -5 = SUICIDAL
The character goes through many episodes in two different game-plays: in one the character has 2 positive episodes, and 8 negative ones, and so goes SUICIDAL: 80% of the episodes were negative.
In another gameplay, the character has 20 positive episodes and 25 negative ones. Character is still SUICIDAL, but actually only 55% of episodes were negative! Something clearly does not work
Taking the hint from the talk above, I’ve implemented a generic class model for Character Trait that considers the whole set of the episodes. The set of states and their level can be injected; moreover you can have a “decay %” so that for each new episode, all previous ones have a decay, so older the episode less relevant it gets (by default decay is 1 so its turned off).
You find the class and a test (for Unity) in this zip. It can clearly be refined ad infinitum in function of specific needs, e.g. having episodes that are both positive and negative and so on.
A couple tests:
Thanks to Daniele Giardini for campaigning for LINQ removal from the code.
Follow me on Twitter where I post about game design, game development, Unity3d 2D, HTML5, applied / serious games.
Update: the Character Trait levels can now be values of an type, not just strings so e.g. if you have an enum of states you can use it as a value. Same download: https://designagame.eu/wp-content/uploads/2017/05/CharacterTrait.zip