I'm interested in researching coding techniques for coding relationships in games. I'm trying to look for resources, but haven't really come across anything yet.
More specifically, in games where playable characters can build relationships with different characters, and especially in games where there is interaction between these relationships. I've heard that the most recent Witcher game is good at this. I imagine that they're not discussing their code openly, but am just using that as an example, if it's helpful.
I would assume the basic technique is to have the non-playable characters have a basic score attached to them that measures their affinity to the playable character which is then effected by player choices. Let's talk about Alice, Bob, and Charlie, where Alice is the playable character, and Bob and Charlie are non-playable (NPCs). I'll throw up some Python psuedocode, assuming separate classes for playable characters :
new Alice(playable):
code would go here
new Bob(nonPlayable):
self.affinity = 0
new Charlie(nonPlayable):
self.affinity = 0
Then if Alice did something nice to/for Bob, maybe it would trigger something that would include:
Bob.affinity += 5
If Bob and Charlie are rivals, and Alice does something nice for Charlie, perhaps it would trigger:
Bob.affinity -= 5
Charlie.affinity += 5
With various events, responses having a requirement of having a relevant affinity score either above or below a certain threshold.
The weakness of such a system is that it only measures affinity to the playable character, and is limited to one trait score, at that. What I mean by the latter is that there's no nuance to it - it's almost as if the NPC totally likes everything about the player, or totally hates everything about them.
I'm hoping for something more dynamic. I'll list a couple complex points, though I'm not necessarily looking for something that covers every single point of nuance here, more for an approach.
- Traits that interpret how characters would react to events. A basic idea might include events that have scores in a few categories, and then characters react based on their own scores. This might be a step in allowing randomly generated characters. Carrying on with the Python examples, I would suppose events should be a class of their own with traits on them:
class Event():
self.courage = 0
self.justice = 0
self.otherTrait = 0
I'm not sure how to really individualize this, though. How would I have the event react to Alice getting along with Charlie and not Bob? What about having a tight working relationship with Bob, but a warmer one with Charlie, though Dana feels competitive with Alice, etc? Put into a more concrete question, how would I code an event to react to a very diverse range of possible factors?
- Nuanced relationships with characters. An NPC might trust a player in combat, but hate them socially. A problem here would quickly become the amount of hardcoded dialogue rising exponentially. This might need the ability to generate text too. If so, this leads to a more concrete question, which is there a known way to generate text conforming to a set of moods and feelings? This would also be a boon in randomly generated NPCs. I was wondering if there's something layered on top of Word2Vec or something like that. -
Thanks!