{"by":"mavdol04","descendants":19,"id":45413208,"kids":[45495428,45494017,45493289,45495071,45495475,45495218,45483597,45500831,45501435,45460721],"score":48,"text":"Hey! I built this system to humanize NPCs by giving them emotions using Rust and ML.<p>The system provides emotion coordinates (based on Russell&#x27;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.<p>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&#x2F;team can manually add dialogues to enrich their own dataset.<p>The matrix doesn&#x27;t generate dialogue, it only analyzes content. When you pass text or an action, it returns emotion coordinates on the valence (pleasant&#x2F;unpleasant) and arousal(energetic&#x2F;calm) scale.\nFor example:<p>- [0.00, 0.00] = neutral<p>- [0.29, 0.80] = excited<p>- [-0.50, -0.30] = sad&#x2F;tired<p>I made a quick visualizer here to help understand  <a href=\"https:&#x2F;&#x2F;valence-arousal-visualizer.vercel.app&#x2F;\" rel=\"nofollow\">https:&#x2F;&#x2F;valence-arousal-visualizer.vercel.app&#x2F;</a><p>The system helps select which dialogue&#x2F;action to play based on emotional state:<p>- Player says something bad to NPC → system detects negative valence → game picks from &quot;angry dialogue pool&quot;<p>- NPC remembers past positive interactions → system returns positive valence → friendlier responses available<p>So, the devs still write the dialogues or choose the next actions, but the matrix helps manage NPC emotional states and memory dynamically.<p>Here&#x27;s the project structure to better understand how it works:<p>- src&#x2F;config: Helper utilities for NPC configuration setup<p>- src&#x2F;module: The core engine with emotion prediction, memory storage, and entity management<p>- src&#x2F;api: FFI layer with pub extern &quot;C&quot; to bridge our modules with C&#x2F;C++ game engines and modding tools (Unity, Unreal, etc.)<p>To implement it, just call `build.sh`, it will create DLL files that you can use to call the matrix functions directly in C++&#x2F;C&#x2F;C#.<p>I&#x27;d love feedback on code quality and overall architecture.<p>Feel free to be honest about the good, the bad, and the ugly. PRs welcome if you want to contribute!","time":1759151134,"title":"Show HN: Neural emotion matrix for NPCs","type":"story","url":"https://github.com/mavdol/npc-neural-affect-matrix"}