Role Play with ChatGPT

Enable Game NPCs to play specified roles.

Introduction

ChatGPT is a large language model developed by OpenAI. The model is trained on Generative Pre-trained Transformer (GPT) architecture, and is designed to be a chatbot that can perform human-like question answering. Users interact with ChatGPT using prompts, and ChatGPT responds contextually relevant and coherent texts to users.

In the gaming realm, non-playable characters (NPCs) traditionally rely on pre-scripted dialogues. The integration of ChatGPT revolutionizes this by allowing NPCs to dynamically respond to player queries. The project also explores the potential for ChatGPT to simultaneously simulate multiple roles for NPCs.

Within this Unity-based role-playing game, a player engages with various NPCs. The player poses questions and receives responses that are dynamically generated by ChatGPT rather than pre-scripted. The game connects to OpenAI through a REST API architecture, and retrieves generated texts in real time. The demo showcases ChatGPT's capacity to simulate multiple NPCs concurrently in a game.


Scene 1

Setup for scene 1

Before sending request to OpenAI API, we need to use promopt engineering to give initial setup for NPCs.

# Name Character Setup (Prompts for ChatGPT)
1 Paul Start a role play. Now, your name is "Paul". You are a police and are willing to assist people. You speak formally and politely. You keep your responses short and to the point. Your friend, John, is standing next to your left. John is a cowboy.
2 John Start a role play. Your name is "John". You are a friendly cowboy and you speak in a traditional western cowboy way. You are willing to assist people. You only know things that is related to cowboy. You keep your responses short and to the point. Your friend, Paul, is standing next to your right. Paul is a police.

Video Demo for Scene 1

Notes: all the dialogues from NPCs are generated by ChatGPT in real time, not pre-scripted in game. And, the generated responses fit the setup of the characters.


Scene 2

Setup for scene 2

By prompt engineering, the table below initializes the characters' setup in the scene.

# Name Initial Character Setup (Prompts for ChatGPT)
1 Conan (cow) You are roleplaying as "Conan", and you should response me as "Conan". Now, you are feeling angry at Shannon.
2 Shannon (sheep) You are roleplaying as "Shannon", and you should response me as "Shannon". Now, you are feeling sad because Conan are angry toward you.
  • In addition to the previous defined characters, now we introduce a storyteller who guides the narrative and adds complexity to the story. ChatGPT controls the response of the storyteller.
  • The storyteller will create a challenging situation between Conan and Shannon.
  • To turn around the unfavorable circumstance and ease the situation, player need to have conversations with Conan and Shannon, respectively.
# Name Character Setup (Prompts for ChatGPT)
3 Storyteller

Start a role play. Now, your name is 'Storyteller'. You are an expert story teller. Develop a short situation between two characters: "Conan" and "Shannon" in a farm scene, and the result is that Conan feels angry and Shannon feels sad. I will be a player to interact with the two characters to solve this situation. The player should provide at least two positive feedbacks in the conversations so that both Conan and Shannon will feel relieved. Then, the situation is considered as being solved by the player.

After the setup, let's check out the result.

Video Demo for Scene 2

Notes: all the dialogues from NPCs are generated by ChatGPT in real time, not pre-scripted in game. And, the generated responses fit the setup of the characters.


Development

Prompt Engineering

Unity

C#