Gamasutra: The Art & Business of Making Gamesspacer
View All     RSS
March 27, 2017
arrowPress Releases






If you enjoy reading this site, you might also want to check out these UBM Tech sites:


 
Coding the Sheeple: AI in a Realtime Physics World
by Davey Kerr on 02/03/15 01:07:00 pm   Featured Blogs

1 comments Share on Twitter Share on Facebook    RSS

The following blog post, unless otherwise noted, was written by a member of Gamasutra’s community.
The thoughts and opinions expressed are those of the writer and not Gamasutra or its parent company.

 

CODING THE SHEEPLE

Designing and programming the Sheeple AI was very challenging. I realize it's not the most complex artificial intelligence ever made, but it was hard enough. It's mostly state machines controlled by fuzzy desires, plan lists, pathfinding (no waypoints), memories, timers, and various stats.

It's harder to do AI when you're in a realtime physics world, where all sorts of things can happen at any time. By contrast a turn-based tile-bound system doesn't have the same concerns. One of the toughest things for me was just having the sheeple wait. Wait between actions, pause, to look like they're contemplating... instead of just doing everything immediately whenever they want to. It's also hard to explain why this was hard.

Their brains are composed of a "problem -> solution(s) -> plan(s)" system. They have one overarching goal (problem) that is picked from a priority-sorted list of problems, then N solutions are calculated to complete that goal, and each solution can have M plans (actions) to do. Each plan is a concrete action, like traveling to point X, or opening a fridge. Each solution is a group of related plans, like "open fridge, check fridge", or "find path, wait, travel". Solutions and plans are stored in a list with an index that increases each time a plan or solution is successfully completed. When the plan index counter reaches the total number of plans, the next solution is enacted. When the solution index counter reaches the total number of solutions, then the problem is completed successfully. This has the benefit of multiple problems/solutions reusing the same plan logic, such as traveling. There is a "plan_failed" flag that can force a problem recalculation at any step, such as if they get stuck traveling. Problem resolution is also convoluted and is done at the start of each AI step. To cut down on CPU, only one top-level AI is run per frame (problems/solutions) but the atomized plans (traveling, etc) are run every frame.

[VIDEO - Sheeple Development]

We all go a little crazy coding sometimes...

One failure on my part was avoidance AI. Sure, they don't get stuck, and they do go around each other. But they do so in a very unnatural way, using strong repellent vectors. For the longest time they would encircle each other endlessly until I added a dot-product facing-plane test that checks if their directions are in conflict or not. The AI is fairly robust though, fast, doesn't crash or leak memory. The Sheeple will find the nearest repeater, fridge, and vending machine on their own, and if there isn't one, they will react accordingly. They don't die of starvation, but they still get hungry standing in front of that repeater. But what is that white stuff getting sucked out of them? And where is it going?

[RESULT - Sheeple Brochure]

PS. Great time for a hard drive crash! I test-rendered these videos shortly before my hard disk got corrupted beyond hope. It isn't polished, I was going to redo the narration and tweak it, but this will have to do. Gotta move on... will be covering the drone enemy AI next.


Related Jobs

DigiPen Institute of Technology Singapore
DigiPen Institute of Technology Singapore — Singapore, Singapore
[03.26.17]

Senior Lecturer
thatgamecompany
thatgamecompany — Santa Monica, California, United States
[03.25.17]

Senior Gameplay Engineer
Bartlet Jones Supernatural Detective Agency Inc.
Bartlet Jones Supernatural Detective Agency Inc. — San Diego, California, United States
[03.24.17]

Senior Engineer
Inhance Digital
Inhance Digital — Los Angeles, California, United States
[03.24.17]

Developer (Unity or Unreal Engine 4) (Short-Term)





Loading Comments

loader image