Behind the Scenes of ROBLOX Hack Week 2015!

During the final week of 2015 the entire ROBLOX staff participates in an event of innovation and creativity called Hack Week.  Amid the engineering creations and experiments some of the coolest visionary ideas of 2015 are presented to the entire company on the final day.  As is tradition we have selected a few of these incredible projects to share with you.  Over the next few weeks the ROBLOX blog will be taking you on a tour of Hack Week by featuring a new project each week.

Remember: there is no guarantee that any of these projects will be transformed into official ROBLOX features, but we’re saying there’s a chance!

Artificial Intelligence in ROBLOX

Laker “UristMcSparks” Sparks

This hack week I decided to explore implementing an Artificial Intelligence framework in ROBLOX. Creating clever NPCs that interact with the world is a great way to make a game come alive and feel immersive. My goal was to create an easily extensible framework that could work for all kinds of autonomous decisions and be utilized in a variety of games. Joining forces with Chris “Silent137” Rider, I set out to see if this was possible in the 5 days of Hack Week.

Some of you may be familiar with my previous work with NPCs. The Drooling Zombie and Soldier from the Toolbox use a simple state machine to guide their actions. This approach works well for simple agents that don’t have many available actions. But what if you want to have a huge set of actions that an NPC can do? Or want the ability to easily add or remove actions? It’s certainly possible with state machines, but it can be a pain in the neck to develop and test.

There is another approach that solves the above problems called Goal Oriented Action Planning (or GOAP for short). Simply put, GOAP is an AI architecture where agents can plan a set of actions that will achieve a certain goal. This has the advantage of supporting a much larger set of actions, while enabling the user to easily add and remove actions for any agent.

To demonstrate this principle in action I created a simple top-down “Sims” style game. My NPCs know how to move between rooms, get food from the fridge, play the piano, and go to the bathroom.

AI-Fridge - roblox star

GOAP Implementation

Let’s take a look at how GOAP works and how I use it in my game. To make a plan of action, our NPCs need several things. Firstly, they need to be able to get a very simplified view of how the world looks. For example, an NPC might need to know if they are bored, or hungry, or in a particular room. Next, they need to have a goal state that they want to be in. Lastly, the NPC needs to know what actions they can take and how those actions affect the world. Using all of this information, the NPC can use a pathfinding algorithm to plot a sequence of actions that will bring them from their current state to their goal.
Let’s look at an example. Here we have an NPC that is standing in the Living Room and is hungry. It has the goal of wanting to not be hungry. So, it figures out the sequence of actions it need to take:

AI-GOAP-Flow - roblox star

Once the NPC has this plan, it puts it into a queue and performs each action one at a time. Let’s take a look at it working in ROBLOX:

AIDemo-gif - roblox star

In this video you can see the scenario I outlined above in action. The NPC starts off hungry and in another room (a bedroom this time instead of the living room). He comes up with a plan to move to the kitchen and get food from the fridge. Throw in a few animations and a wonderfully built environment (provided by the user 101PILOT), and you get an interesting NPC who can interact with his surroundings.

 

I plan to continue working on this project. Ultimately I would like to release this as a module or a plugin you could use to make NPCs in your games.

If you are interested in learning more about GOAP, I highly recommend starting with this article:http://gamedevelopment.tutsplus.com/tutorials/goal-oriented-action-planning-for-a-smarter-ai–cms-20793

There is also a repository of articles and examples here: http://alumni.media.mit.edu/~jorkin/goap.html

Thanks for reading!

Laker “UristMcSparks” Sparks

 

Add a Comment

Your email address will not be published. Required fields are marked *