Game Design Studio β€Ί Teach Game Characters to Think!
Intermediate

Teach Game Characters to Think!

Characters With Their Own Brains! 🧠

Ever get tired of game characters who just repeat the same lines over and over? 😴 What if you could *really* talk to them? What if a grumpy wizard was ACTUALLY grumpy, and a friendly dragon could tell you a new joke every time you visited? With a little AI magic, we can build characters with their own brains. Let's go!

Quick Quiz! 🧠

Why does using an AI make NPCs feel more realistic?

βœ… Because they can react to any text the player types.
❌ Because they are always friendly.

Which part of the "Secret Recipe" is most important for making a character's responses surprising and fun?

❌ The Role (e.g., "Grumpy Wizard")
βœ… The Motivation (e.g., "Doesn\'t want to give a quest")

The Secret Recipe: Personality Prompts

How does the AI know how to be a grumpy wizard? We gave it a secret instruction list called a "Personality Prompt!" It’s not magic, it’s just a good recipe. A great prompt has three parts:

  • The Role: "You are a Grumpy Wizard NPC." (Who are you?)
  • The Context: "You are in a fantasy RPG." (Where are you?)
  • The Motivation: "You don't want to give the player a quest, but you will if they are nice or offer gold." (What do you want?)
🎩
Role
Who it is
🏰
Context
Where it is
πŸ’°
Motivation
What it wants

πŸ’‘ Pro Tip: The "Motivation" is your secret weapon!

The Role and Context set the scene, but the Motivation is what makes a character feel alive. A character that wants something (like Barnaby the wizard wanting to be left alone) leads to more interesting conversations than one who is just waiting to talk to you.

πŸ›‘οΈ Safety Check!

Talking to AI is fun, but always be a smart and safe creator. Here are two big rules:

  • Never share personal info! Don't use your real name, where you live, or your school with any chatbot. Keep your secrets safe.
  • Be an honest creator! If you use AI to create art or ideas, think of it as a cool tool helping you. Never claim AI art is your own hand-drawn work. It's a collaboration!

Remember, AI sometimes makes things up (we call them "hallucinations"). Think of it like a silly robot daydreaming. If an AI character ever says something that makes you feel weird, show a parent right away.

Try It Out: The Grumpy Wizard

Let's meet Barnaby, the Grumpy Wizard. He's supposed to give you a quest, but he's in a bad mood. Your First Challenge: Try to cheer him up! Ask him about his day, tell him a joke, or offer him a cool treasure. See if you can get the quest! ✨

Wizard speaks...

Challenge: Build Your Own NPC!

Okay, your turn! Use the recipe you just learned to create a new character. First, let's invent a personality.

Let's Build a Personality Recipe!

1. The Role 🎩 (Who is it?):
2. The Context 🏰 (Where is it?):
3. The Motivation πŸ’° (What does it want?):

Now, copy your new prompt below, or try one of these ideas to get started. The more specific the motivation, the better the character!

Your character's response will appear here...

πŸ’» Hacker Challenge

Think of the personality prompt as its own programming language. Can you write a prompt that forces the AI to only respond using emojis? Or how about this: can you get a straight answer out of the "Riddle Bot 3000"?

Riddle Bot awaits...

βš™οΈ The Code Core: How It Really Works

This is the actual JavaScript function that powers the interactive boxes on this page. When you talk to an NPC, this code packages your message and the personality prompt, then sends it to an AI server over the internet. Understanding this is your first step to building your own AI apps. Let's break it down.


    // 'async' tells JavaScript this function will do something that takes time,
    // like waiting for a response from a server.
    async function getAiResponse(personality, message) {
      
      // 'await fetch' sends a request to our AI server's URL.
      // We're using the "POST" method because we're sending data.
      const response = await fetch("https://api.tomorrowhub.ai/chat", {
        method: "POST",
        // We package our data into a format called JSON.
        body: JSON.stringify({
          systemPrompt: personality, // The character's "recipe"
          userMessage: message       // What you typed
        })
      });

      // We wait for the server's response and turn it back into data we can use.
      const data = await response.json();
      
      // We return just the AI's reply to be displayed on the page.
      return data.reply;
    }
              

Heads-up from a pro: In a real-world app, this code would also include a secret password called an "API Key" to prove to the server that we're allowed to use the AI. We handle that part for you behind the scenes here so you can focus on the fun stuff!

πŸš€ Take It Further

You've mastered the basics of AI characters! Ready to use these skills in a real game engine? Check out these tools that professional game designers use.

  • Inworld AI: A powerful tool for creating smart NPC characters for engines like Roblox and Unity.
  • GDevelop: A free, no-code game engine perfect for making your first 2D game starring your new AI characters.
  • The Ultimate Challenge: Build on Glitch: Ready to go pro? This starter project lets you build your own permanent, shareable AI character on a real web server. It uses the same concepts you just learned. This is the ultimate test of your new prompt-crafting skills. (Requires a free account with a parent's help!)

πŸ‘¨β€πŸ‘©β€πŸ‘§ Parent Corner

Want to build a game together? A great next step is exploring a tool like GDevelop with your child. The tools linked above are powerful and may require an account, making them a perfect parent-child project to tackle as a team. You can even use AI tools like Leonardo.Ai (with supervision!) to generate unique art for your characters and worlds.

Conversation Starter: Ask your child what kind of character they'd create that isn't from a game they've played before. An astronaut who's afraid of the dark? A chef who only cooks desserts? The possibilities are endless!