Bring AI Characters to Web Browser-Based Virtual Worlds Using Convai and PlayCanvas

By
Convai Team
November 6, 2024

The merging of artificial intelligence (AI) and virtual worlds has transformed web browser-based experiences, offering new ways to engage users with immersive, interactive, and responsive characters. With platforms like PlayCanvas and Convai’s SDK, developers can now integrate AI characters directly into their virtual worlds, unlocking possibilities for interactive storytelling, game mechanics, and AI-driven non-playable characters (AI NPCs). Learn more about how AI characters are revolutionizing gaming and other industries in our article which dives deep into AI gaming trends in 2024. This blog dives into how Convai’s capabilities align with PlayCanvas to help developers add AI-powered characters to their projects and why this duo is a solid choice for building multi-platform, lightweight, and future-proof experiences on the web filled with AI-powered characters.

Follow our detailed step-by-step video tutorial and start creating your own browser-based virtual worlds with AI Characters today!

Also, feel free to test out the PlayCanvas Demo yourself and reach out to us with any feedback or appreciation! 

Why Browser-Based Virtual Worlds with AI?

Creating browser-based virtual worlds with PlayCanvas offers incredible advantages, particularly when enhanced with AI characters:

1. Multi-platform Flexibility: Web experiences developed with PlayCanvas can reach users across different devices with no need for complex setup.

2. Futureproofing with WebGPU: PlayCanvas already supports WebGPU, which is in beta and promises higher performance graphics, making your projects ready for the future.

3. Lower Hardware Requirements: Browser-based games often need less computer power than downloadable ones, which means accessibility for a broader audience.

4. Open-Source and Collaborative: PlayCanvas’s open-source nature allows easy collaboration and community-driven improvements.

5. Enhanced Interaction: AI NPCs bring worlds to life, letting users interact naturally and dynamically within their environment.

Here’s an interesting user post we found on the PlayCanvas forum, which dives into the simplicity and the beginner friendly nature of PlayCanvas

Convai’s SDK for PlayCanvas

Convai’s SDK enables adding powerful LLM-based AI capabilities to your PlayCanvas projects, turning regular NPCs into intelligent characters that can converse naturally, understand their surroundings, and perform actions—all within a browser setting. Let’s explore the steps and best practices to bring AI characters into your PlayCanvas project, followed by examples of use cases and key benefits for developers.

Getting Started: Convai and PlayCanvas Integration

Step 1: Setting Up Your PlayCanvas Project

To get started, follow the Convai SDK for PlayCanvas documentation, which guides you through initial setup and configuration. You can either create a new project from scratch or use a PlayCanvas template provided by Convai. The template simplifies integration by setting up the core structure for AI-enabled characters and includes various assets and scripts for handling NPC behavior.

PlayCanvas SDK Project Includes camera, light, and player objects, along with the Convai NPC setup.

Step 2: Adding AI Characters with Convai

Once the base project is ready, you’ll add AI NPCs that leverage Convai’s SDK. Here’s how to do it:

1. Import NPC Assets: You can either use preset avatars or bring custom characters, such as Ready Player Me avatars, to the scene.

2. Set Up Chat UI: Integrate Convai’s chat UI so users can communicate with the AI NPCs. Convai’s tools enable creating a natural chat interface within PlayCanvas for seamless in-game interactions. Here’s the chat UI script for ease of integration.

3. Add Animation States: Implement animations like  idle, talking, and walking states to enhance character realism.

Step 3: Integrating Actions and Interaction

With Convai’s SDK, AI NPCs can go beyond passive roles and respond to user actions in the virtual environment. Here’s a look at some functions and configurations you’ll use to bring this interactivity to life:

- Action Handlers: Use Convai’s built-in action handlers for gestures or animations based on user input.

- Environmental Awareness: NPCs can recognize and react to specific objects or settings, making them feel like part of the world.

- Dynamic Responses: The AI NPCs generate contextual responses that adapt based on user interaction, creating a more personalized experience.

Custom Character Integration: Bringing Unique Avatars to Life

Adding unique characters to your virtual world increases user engagement and provides tailored experiences. Convai supports multiple custom character sources, including Ready Player Me avatars and Reallusion ActorCore models.

Using Ready Player Me Avatars

With Convai’s SDK, AI NPCs can go beyond passive roles and respond to user actions in the virtual environment. Here’s a look at some functions and configurations you’ll use to bring this interactivity to life:

- Action Handlers: Use Convai’s built-in action handlers for gestures or animations based on user input.

- Environmental Awareness: NPCs can recognize and react to specific objects or settings, making them feel like part of the world.

- Dynamic Responses: The AI NPCs generate contextual responses that adapt based on user interaction, creating a more personalized experience.

Custom Character Integration: Bringing Unique Avatars to Life

Adding unique characters to your virtual world increases user engagement and provides tailored experiences. Convai supports multiple custom character sources, including Ready Player Me avatars and Reallusion ActorCore models.

Using Ready Player Me Avatars

ActorCore characters offer more customization for cinematic scenes or high-quality game elements. The steps are similar to Ready Player Me integration but include a few unique features:

1. Download FBX Files: Export your ActorCore characters from Reallusion.

2. Convert to GLB using Blender: Use Blender to convert the files, ensuring compatibility with PlayCanvas.

3. Configure Animations: Set up animations like idle or walking to bring these characters to life in your browser-based world.

Best Practices for AI NPCs in Virtual Worlds

When developing AI characters for browser-based virtual worlds, keep these best practices in mind:

1. Optimize Performance: Always monitor memory and resource usage, especially for complex AI interactions.

2. User-Friendly Interaction: Make chat UIs and actions intuitive; this helps players feel comfortable engaging with AI NPCs.

3. Clear Story and Purpose: Give your AI characters a defined role or background, which improves immersion and makes the interaction more engaging. To get started with Convai, read our documentation page.

4. Regular Updates: Because AI and web technologies evolve, keep your project updated to ensure the best user experience.

5. Consider Privacy and Data: If your game tracks user data or responses, comply with relevant data protection regulations.

Sample Table for AI NPC Actions

Action Type

Description

Usage Example

Conversational 

Natural dialogue capabilities

Interacting with a tour guide 

Environmental 

Responds to objects nearby 

Noticing a statue in the scene

Task-Oriented

Performs specific actions

Guiding the user to locations

Contextual 

Adapts based on user actions

Changes behavior on user input

Future of AI NPCs in Web-Based Virtual Worlds

With the rapid progress of AI and web technology, PlayCanvas and Convai are setting a standard for virtual world creation on the browser. As WebGPU matures, developers will achieve even better graphics and performance, enabling larger-scale, interactive environments without the need for heavy client-side setups. 

Potential Use Cases

- Digital Twins for Learning: Educational simulations that use AI characters as digital trainers or tour guides.

- Interactive Storytelling: Web-based role-playing games (RPGs) with AI NPCs that adapt the story based on player choices.

- Multiplayer AI: Bringing AI into multiplayer environments to provide cooperative or competitive AI teammates. Start building multiplayer experiences on Unreal Engine today following our tutorial.

Conclusion

Creating AI NPCs for web-based virtual worlds is no longer a complex challenge thanks to platforms like PlayCanvas and Convai’s AI integration. By combining multi-platform flexibility, future-proofing through WebGPU, and ease of development with Convai’s SDK, developers can build engaging and interactive worlds accessible to a vast audience. Whether for gaming, learning, or immersive storytelling, browser-based virtual worlds with AI characters are an exciting frontier with endless possibilities.

Sign up at https://convai.com to try it out. Also, subscribe to this YouTube channel and stay updated with our latest developments. Write to us at support@convai.com for any queries, bug reports, collab, or business-related engagement.