3
\$\begingroup\$

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!

\$\endgroup\$
13
  • 2
    \$\begingroup\$ I really would like to write an answer to this question. But unfortunately it is not yet clear what you need. Can you add more details about what situations you want to have in your game and what the relationship system should do in these situations? One possible approach could be a system where you don't track a score but keep track of events which affect the relationship between two characters and use those to calculate responses ad-hoc. But in order to help you design such a system we need to know more about your exact requirements. \$\endgroup\$ – Philipp Jun 7 '19 at 11:57
  • 2
    \$\begingroup\$ What we're best at helping with here are "I want to achieve this specific outcome, how can I do it?" or "I'm experiencing this specific problem, how do I solve it?" rather than "list all the ways games might approach this general feature area". As Philipp says, if you're able to edit this question to make it more about achieving a particular kind of relationship system with specific behaviours, we can re-open it and suggest ways to execute that specific design. \$\endgroup\$ – DMGregory Jun 7 '19 at 12:04
  • 3
    \$\begingroup\$ Chat would be a great place to discuss open-ended design questions like this. There are lots of approaches you could take. \$\endgroup\$ – Chuck Jun 7 '19 at 12:15
  • 2
    \$\begingroup\$ @trollingchar I made this account now, so I sadly don't have 20 reputation to be able to access chat. \$\endgroup\$ – Colliander Jun 7 '19 at 12:55
  • 2
    \$\begingroup\$ I'd say it now has too many questions. Imagine you're making one game with just one version of this system, that needs to handle exactly these X scenarios. Ask about one feature in that game — ie. either relationship management or generated text, not both (a solution to one doesn't solve the other) \$\endgroup\$ – DMGregory Jun 7 '19 at 13:27