- Introduction
- System Components
- Setup and Configuration
- Usage
- Examples
- Use Cases
- Offline Mode
- Best Practices
The Immersive Hint System is a flexible and powerful tool designed for Unity games, leveraging OpenAI's GPT models to provide dynamic, context-aware hints and responses to players. This system allows for personalized AI interactions, adapting to the game's current state, player actions, and predefined lore.
Key features include:
- Dynamic personality adjustment
- Context-aware responses
- Integration of static and dynamic lore
- Offline mode support
- Customizable prompt templates
The Immersive Hint System consists of several interconnected components:
-
GPTHintSystem: The core component that manages API requests, context building, and response generation.
-
AIPersonality (ScriptableObject):
- Purpose: Defines the AI's base personality and emotional modifiers.
- Functionality:
- Stores a base personality description.
- Contains a list of emotion modifiers that can alter the AI's responses based on different emotional states.
- Provides a method to get a personality prompt based on a given emotion.
-
StaticLore (ScriptableObject):
- Purpose: Contains unchanging background information about the game world.
- Functionality:
- Stores a list of lore entries that remain constant throughout the game.
- Provides a foundation for the AI's knowledge about the game world, characters, and history.
-
DynamicLore (ScriptableObject):
- Purpose: Stores and manages evolving game events and player actions.
- Functionality:
- Maintains a list of entries that can be added, removed, or cleared during gameplay.
- Allows the system to adapt its responses based on the current game state and player progress.
-
PromptTemplates (ScriptableObject):
- Purpose: Provides customizable templates for structuring requests to the GPT model.
- Functionality:
- Stores a list of named prompt templates.
- Allows developers to create different templates for various types of interactions (e.g., quest hints, NPC dialogues).
- Provides a method to retrieve a specific template by name.
-
OfflineResponseDatabase (ScriptableObject):
- Purpose: Stores pre-defined responses for offline use.
- Functionality:
- Contains a list of keyword-response pairs.
- Provides fallback responses when the system can't connect to the OpenAI API.
- Allows for basic functionality even without an internet connection.
-
GameEventManager: Facilitates the addition and removal of game events to the dynamic lore.
-
Create the necessary ScriptableObjects:
- AIPersonality
- StaticLore
- DynamicLore
- PromptTemplates
- OfflineResponseDatabase
-
Attach the
GPTHintSystem
script to a GameObject in your scene. -
Configure the
GPTHintSystem
in the Inspector:- Set your OpenAI API key
- Choose the desired GPT model
- Assign the created ScriptableObjects to their respective fields
-
Set up the
GameEventManager
:- Attach it to a GameObject (can be the same as
GPTHintSystem
) - Assign the
GPTHintSystem
andDynamicLore
references in the Inspector
- Attach it to a GameObject (can be the same as
To get a response from the Immersive Hint System:
public class GameManager : MonoBehaviour
{
public GPTHintSystem hintSystem;
public async void GetHint(string playerQuestion)
{
string response = await hintSystem.GetResponse(playerQuestion);
DisplayHintToPlayer(response);
}
private void DisplayHintToPlayer(string hint)
{
// Implement your UI logic here
}
}
To update the game state and influence AI responses:
public class QuestManager : MonoBehaviour
{
public GameEventManager eventManager;
public void CompleteQuest(string questName)
{
string eventDescription = $"Player completed the quest: {questName}";
eventManager.AddGameEvent(eventDescription);
}
}
To adjust the AI's emotional state:
public class DialogueManager : MonoBehaviour
{
public GPTHintSystem hintSystem;
public async void GetNPCResponse(string playerDialogue, string npcEmotion)
{
string response = await hintSystem.GetResponse(playerDialogue, npcEmotion);
DisplayNPCResponse(response);
}
}
string playerQuestion = "Where should I look for the lost artifact?";
string hint = await hintSystem.GetResponse(playerQuestion, "helpful", "quest_hint");
// hint might be: "Based on the ancient texts in the library, the lost artifact is rumored to be hidden in the Whispering Caves to the north of the village."
string playerDialogue = "Can you tell me about the war that happened 100 years ago?";
string npcResponse = await hintSystem.GetResponse(playerDialogue, "somber", "npc_dialogue");
// npcResponse might be: "Ah, the Great Conflict. *sighs* It's not a tale I enjoy recounting. So many lives lost, so much destruction. What specifically would you like to know about those dark times?"
- Dynamic Hint System: Provide players with contextual hints that adapt to their progress and game state.
- Intelligent NPCs: Create more engaging and responsive non-player characters that react to the player's actions and game events.
- Adaptive Storytelling: Generate dynamic narrative elements that respond to player choices and game progression.
- Tutorial Assistant: Offer a smart tutorial system that can answer player questions and provide guidance based on their current situation.
- Puzzle Solver Aid: Give subtle, context-aware clues for complex puzzles without explicitly solving them for the player.
The system includes an offline mode for situations where internet connectivity is unavailable:
- Populate the
OfflineResponseDatabase
with keyword-response pairs. - The system automatically switches to offline mode when it can't connect to the OpenAI API.
- Responses are selected based on keyword matching from the player's input.
Example of populating the OfflineResponseDatabase:
offlineResponseDatabase.responses.Add(new OfflineResponseDatabase.OfflineResponse
{
keyword = "lost artifact",
response = "The lost artifact is an object of great power. Many have searched for it in the ancient ruins to the east."
});
- Maintain Consistency: Keep your StaticLore, DynamicLore, and AIPersonality consistent to ensure coherent responses.
- Optimize API Usage: Use the prioritized context feature to ensure the most relevant information is included in each request.
- Balance Information: Provide enough context for informative responses, but avoid overloading the system with unnecessary details.
- Test Offline Responses: Ensure your offline database covers common player questions and critical game information.
- Update Dynamic Lore: Regularly update the dynamic lore as the game state changes to keep responses relevant and accurate.
- Emotion Variety: Utilize different emotions in the AIPersonality to create more engaging and varied interactions.
- Prompt Engineering: Refine your prompt templates to guide the AI towards producing the desired style and content of responses.