Goal Oriented Action Planning

Posted on 25-09-2016

In the final year of the HKU you get 4 months to research and develop a subject to your liking. Being really excited to receive so much freedom, I quickly found out it wasn’t that easy to find a subject. After all, I was stuck between two major themes which have always peaked my interests as a developer, mainly creating tools and Artificial Intelligence. Luckily my mentor recently read about Goal Oriented Action Planning (Henceforth referenced to as GOAP), an underdeveloped way to handle AI, and pitched it to me. With both of my main interests being fulfilled, it was a no brainer to go with GOAP. Within my graduation project I set out two goals for myself: Create a setup which will allow for easy re-usability, and research how different video games use GOAP.

A basic editor I wrote which allows designers to easily create behaviour by changing actions and goals

GOAP, simply enough, boils down to three major components which allow a designer to quickly create AI behavior.
The first component is actions. Actions are small specific things an AI can do, like walking, opening a door or shooting a gun. All actions have a list of preconditions and effects. The action ‘ShootGun’ could have the precondition “HasGun, true”, while the effect would be “TargetKilled, true”.

The seconds component is goals. Unlike actions which impact the game directly, goals are more like guidelines. A goal could be general like ‘Loot all bodies’, or be more specific like ‘Kill target player’. A goal consists of an array of succes factors, which for the goal ‘Kill target player’ could look like “TargetKilled, true”.

A entity shooting at another entity, by using the ‘AttackRanged’ action

The third component is the planner, the algorithm which ‘makes the magic happen’. The planner finds all viable goals, and picks the one with the highest priority. It starts by taking the succes rate of this goal, and tries to find a action which effects state matches the goals succes state. If these states match, it removes the effects state, adds the actions precondition state and adds the action to a list. It keeps on repeating the process with the newly found state until the state is empty. If multiple actions match the state, the action with the lowest cost will be picked.

Goal Oriented Action Planning gets rid of traditional statemachines, and creates a easy and clear layout for actions

With GOAP character behavior can easily be changed by giving the character additional actions and/or goals, without ever having to touch a statemachine. Adding to the dynamic system, multiple actions can be used to achieve the same goal. Want human characters to open a door? Just give them the ‘OpenDoor’ action. Want brutish orc characters to smash a door? Simply give them the ‘SmashDoor’ action. Both achieve the same goal, namely opening said door, but give different behavior.

A entity fulfilling it’s ‘KillTarget’ goal, and continuing it’s ‘Patrol’ goal afterwards

At 17-10-2016 my GOAP asset was published on the Unity asset store. You can buy it here.