Wednesday, December 4, 2013

Goal-Oriented Action Planning

Goal-oriented action planning (GOAP) is a technique used to enhance the ways that NPCs make decisions, in order to make them seem more lifelike than if they were using a state machine. With a finite state machine (FSM), NPCs are constrained to follow basic rules - "If my health is below x%, then do y." "If I see the player, start chasing it." GOAP allows the AI a bit more freedom on what to do in order to achieve their goal. The AI has a set of goals it is trying to complete, and actions that it can take to affect those goals. Each action will have an affect on one or more goals, and the AI will choose the action that will best satisfy the current goals at that moment. To use an example that would apply to a real-life scenario, the AI may have a goal to eat, and a goal to sleep. Each goal has a value that represents how urgent that goal is, and those values are all calculated together to form a "discontentment" value. The AI would then cycle through each action it has available to it and figure out which action will lower the overall discontentment the most, and perform that action.

In the tech demo linked below, there are 4 goals that each unit follows: Gathering food, wood, and gold, and keeping its energy level up. To accomplish these goals, there are 5
different actions they can take - again, gathering food, wood, and gold, and eating food or sleeping to recover energy. Running this simulation gives a simple demonstration of how GOAP works in a game. Pressing the + and - buttons will add or delete units, respectively, and clicking on a unit displays the available actions and the estimated discontentment level after the action is performed.

This technique can be applied in a great number of game genres. Like the demo shows, real-time strategy games are a prime example of a type of game that can greatly benefit from GOAP, but other games can get just as much use out of it. Some of the first games that used GOAP were No One Lives Forever 2 and F.E.A.R., both of which are first-person shooters, and both were highly regarded for their innovation in AI. Another example that is probably fairly obvious is a game like The Sims, where the goals would be the needs that each Sim has and the actions would be the available options to affect those needs. Almost every game could find a good use for GOAP as a way to enhance their AI.


Tech Demo


Sources:

No comments:

Post a Comment