[HN Gopher] Show HN: Neural emotion matrix for NPCs
___________________________________________________________________
Show HN: Neural emotion matrix for NPCs
Hey! I built this system to humanize NPCs by giving them emotions
using Rust and ML. The system provides emotion coordinates (based
on Russell's circumplex model) from text input or actions, with
persistent emotional memory per entity. Think NPCs that remember
how they feel about specific players or events. I pre-trained a
DistilBERT model on ~1k video game dialogues (Skyrim, Cyberpunk,
etc.) and plan to extract and evaluate 100k+ dialogues soon.
However studio/team can manually add dialogues to enrich their own
dataset. The matrix doesn't generate dialogue, it only analyzes
content. When you pass text or an action, it returns emotion
coordinates on the valence (pleasant/unpleasant) and
arousal(energetic/calm) scale. For example: - [0.00, 0.00] =
neutral - [0.29, 0.80] = excited - [-0.50, -0.30] = sad/tired I
made a quick visualizer here to help understand https://valence-
arousal-visualizer.vercel.app/ The system helps select which
dialogue/action to play based on emotional state: - Player says
something bad to NPC - system detects negative valence - game picks
from "angry dialogue pool" - NPC remembers past positive
interactions - system returns positive valence - friendlier
responses available So, the devs still write the dialogues or
choose the next actions, but the matrix helps manage NPC emotional
states and memory dynamically. Here's the project structure to
better understand how it works: - src/config: Helper utilities for
NPC configuration setup - src/module: The core engine with emotion
prediction, memory storage, and entity management - src/api: FFI
layer with pub extern "C" to bridge our modules with C/C++ game
engines and modding tools (Unity, Unreal, etc.) To implement it,
just call `build.sh`, it will create DLL files that you can use to
call the matrix functions directly in C++/C/C#. I'd love feedback
on code quality and overall architecture. Feel free to be honest
about the good, the bad, and the ugly. PRs welcome if you want to
contribute!
Author : mavdol04
Score : 38 points
Date : 2025-09-29 13:05 UTC (7 days ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| oneandonley1 wrote:
| >call the matrix functions directly in C++
|
| Sweet so it can be used in unreal engine it would be awsome to
| see this used for a local llm game that can generate it's own
| unique NPCs
| mavdol04 wrote:
| Thanks, that's an interesting idea! Some games need predictable
| dialogue, but as an option it could be great
| mvieira38 wrote:
| Excited for stuff like this as a CRPG player. A possible future
| for designing a crpg NPC might be to write a bunch of memories,
| descriptions, likes and dislikes, etc. in text instead of trying
| to convey those through branching dialogue.
| mavdol04 wrote:
| Yeah, that's the kind of direction I'm hoping for too. It could
| be hard to follow a narrative without branching dialogue, but
| maybe it will raise a new kind of NPC
| 7373737373 wrote:
| Is this related to https://qualiacomputing.com/2020/12/17/the-
| symmetry-theory-o...?
| mavdol04 wrote:
| Probably I haven't read the whole article, but it seems to be
| based on the Russell circumplex model of affect
| (valence/arousal).
|
| https://www.researchgate.net/publication/235361517_A_Circump...
| bbminner wrote:
| Could you provide an example conversation that showcases the
| quality? For example either inferring states of npcs and re-
| ranking response options?
|
| Kind of reminds me of the social interaction puzzle in oblivion
| :)
| mavdol04 wrote:
| I plan to work on a Skyrim follower mod to showcase this in
| action. Meanwhile, you can try a short conversation example in
| main.rs if you want to test it without using C++ :)
| Arch485 wrote:
| Is there any specific reason to use this over e.g. manually
| setting an "emotional score" for specific dialogue? Maybe I'm
| misunderstanding how this works, but from a game design
| perspective I'd be a bit worried about the model inferring the
| emotion incorrectly, or more generally having a lack of control
| over the specific values being used.
| mavdol04 wrote:
| Good question! Actually, it complements manual settings. There
| are many use cases but for example, in some games with multiple
| followers. You sometimes get bugs where they fight each other
| randomly for some reason. With this system, you could check
| their emotional state toward each other before triggering
| combat, and if they're actually friendly, you prevent the
| unintended fight
| Archelaos wrote:
| Isn't the whole system somewhat too limited? An interaction can
| be unpleasant and pleasant at the same time, like getting food
| offered I dislike when I am very hungry. Instead, shouldn't it be
| preferable to model the inner state of NPCs with a high
| dimensional vector space plus fading memory? Folk psychology
| emotions could than be interpreted as reductions of this high
| dimensional vector space. We also could use a part of the vector
| space for a dynamic feedback system, such as adjusting the fading
| of a particular memory depending on particular values (intens
| events remain longer in memory, ...) an overall condition
| (repeated recent events remain longer in memory; certain recent
| events in close proximity in the vector space improve their
| memorization, ...), other memories, etc.
| mavdol04 wrote:
| That's super interesting. Yeah, the 2D model has limitations
| for sure. Actually, we have a memory decay system with time,
| but nothing as elaborate as what you're describing. I'm curious
| to know more about your idea. Theoretically, how would you
| imagine separating memories? Would you use memories clusters
| with different weight for example ?
| nathan_douglas wrote:
| This is really cool - the sort of thing I love seeing on HN. I'm
| very deeply interested in developing/interacting with realistic
| characters within a game world and watching them interact with
| another, e.g. intertribal/interpersonal squabbles in a kobold
| tribe, that kind of thing. I think the potential for this sort of
| experience in gaming is really untapped and is going to be
| incredible.
| mavdol04 wrote:
| Thank you! Yeah, there are many use cases. The goal is really
| to expand what's possible with NPC interactions and emergent
| behaviors
___________________________________________________________________
(page generated 2025-10-06 23:01 UTC)