How to Play Animation with Open AI NPC Freeform Chat

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Mchaint
Posts: 7
Joined: Sun Mar 03, 2024 9:16 pm

How to Play Animation with Open AI NPC Freeform Chat

Post by Mchaint »

Hi Tony,
I am currently developing a VR game, I am trying to make the AI NPC to Play certain Animation during freeform conversation, for example, if Player asks "Can you show me how to dance?" then AI NPC plays dance animation.
Also, if Player asks "Can you pick up that Gun for me?" then AI NPC picks up the gun and give it to the Player by playing that pick up animation.

Image

I thought I need to use Variables and Boolean, but I don't know where to write the sequencer command "AnimatorPlay" for this scenario.
Please guide me how to make this happen.
Thank you so much :)
User avatar
Tony Li
Posts: 22871
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to Play Animation with Open AI NPC Freeform Chat

Post by Tony Li »

This is something that even the AAA studios are still figuring out. I assume you're using the Dialogue System Addon for OpenAI's RuntimeAIConversation component. If so, one idea is to additionally specify something like "If the player asks {NPC} to perform an action, print that action in square brackets such as [dance]." You could add it to the Topic field. Then make a subclass of RuntimeAIConversation and override the OnReceivedLine() method to look for text that contains square brackets. It may take some experimentation to arrive at a prompt that returns what you want.
Mchaint
Posts: 7
Joined: Sun Mar 03, 2024 9:16 pm

Re: How to Play Animation with Open AI NPC Freeform Chat

Post by Mchaint »

Oops, ok, haha, I saw this Convai AI Asset on Unity Asset store, in the video, AI-NPC picking up the rifle and hand it to the player,
so I thought it is something I can also do with dialogue system OpenAI Addons.
https://assetstore.unity.com/packages/t ... vai-235621

This is their video

User avatar
Tony Li
Posts: 22871
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to Play Animation with Open AI NPC Freeform Chat

Post by Tony Li »

Yeah, some of those things are very bespoke. It's possible, but like with Convai you need to do a bit of setup.
Rantannew
Posts: 1
Joined: Fri Mar 21, 2025 1:15 pm

Re: How to Play Animation with Open AI NPC Freeform Chat

Post by Rantannew »

Hi there!

It sounds like an exciting project you're working on! To implement the AI NPC's animation behavior based on player interaction, you're on the right track with using variables and booleans. Here's a general approach that might help you structure this:

Create Trigger Conditions:

For each player request (e.g., "Can you show me how to dance?" or "Can you pick up that gun?"), you'll want to set up a trigger condition. This could be based on specific keywords from the player's input or by using a dialogue system to detect player intent.
Use Animator Controller:

In Unity, for example, you would want to use an Animator Controller for your NPC. The Animator Controller allows you to set up different animation states (like "Dance," "Pick up," etc.) and control how these states transition based on certain parameters.
Set Parameters in Animator:

You can create parameters in the Animator, like a Boolean (e.g., isDancing, isPickingUp) or a Trigger (e.g., startDance, pickUpGun), that will control the transitions between different animation states.
Script the Logic:

You'll need to write some scripts in C# (or your preferred language) to handle the player input and trigger the appropriate animation. For example:
csharp
Копировать
public Animator npcAnimator;

void Update() {
// Check player input and set animation triggers
if (PlayerRequestsDance()) {
npcAnimator.SetTrigger("startDance"); // Trigger the dance animation
}
else if (PlayerRequestsPickUpGun()) {
npcAnimator.SetTrigger("pickUpGun"); // Trigger the pick up gun animation
}
}

bool PlayerRequestsDance() {
// Logic to detect if the player asks to dance
return Input.GetKeyDown(KeyCode.D); // Placeholder for actual input logic
}

bool PlayerRequestsPickUpGun() {
// Logic to detect if the player asks to pick up the gun
return Input.GetKeyDown(KeyCode.P); // Placeholder for actual input logic
}
Handle Animations:

Once you've set up the transitions in the Animator with the necessary conditions (e.g., startDance, pickUpGun), when those parameters are triggered via your script, the NPC will play the correct animation.
Fine-Tuning:

If the animation includes complex actions (like picking up the gun and handing it to the player), you might need to use more advanced animation techniques, such as animation events, to trigger specific actions (e.g., physics-based interactions for picking up objects).
Let me know if you need further clarification or help with a specific part of the process!
I use the chat from website in my work, namely for writing articles. This is useful software.
Post Reply