Happy New Year!
Been a little while since I posted something, mostly out of laziness but I've worked pretty much every day in December, polishing existing systems and implementing new ones.
A couple of things I've been working on was first a complete refactor of how I handled certain animations and motion and have switched over to a Root Motion work flow. More on that another time.
The big thing I was designing and finally got working in a (mostly) efficient and scalable way was the Goal Oriented Action Planning AI system, or G.O.A.P., much like the one that was built and used in the video game F.E.A.R. from 2005.
My initial attempt at building an AI was to use a state machine, but as I needed more and more states and saw myself duplicating a lot of the same code for different types of units, I felt the need for something better. And after watching a talk on AI and Games with Dr Jeff Orkin, the AI programmer on F.E.A.R., I was determined to try it out and see if it would work for my use cases.
How GOAP works is like this. You have an agent and you provide it with a goal, an ability to get information about the world state, and a list of actions it can take. Each action has a set of conditions for the world state, what the world state will be after the action is completed, and the cost to take that action.
All of this, the goal, the world state, and the available actions are then fed into a Planner which will do a path find using A* to figure out what order of actions would arrive at the goal the quickest.
A basic diagram of this process
This means that for each agent type, I no longer needed to build a way to tell each agent what to do and when, only how to carry out the individual actions and let the GOAP planner figure it out for itself.
So for example, lets say I have a goal to patrol along a path. Below is a diagram of how that goal might be deconstructed into the individual actions needed to meet and keep the world state desired by the goal.
As the agent does things in the world, the state will of course change. And depending on the nature of that state change, it might require the planner to build a new list of actions. If we have two goals for example, one being to patrol an area and the other to engage the target. The agent is patrolling when it's receives a signal that it can now see a target that it should engage. The planner rebuilds it's plan and issues the new instructions to the agent to go do what it needs to accomplish that goal.
Now, by letting the GOAP planner handle what to do with the agent and it's state, all I needed to do was to manage and keep that state updated which I still use a state machine for but it's much less complex.
I will have some video of GOAP in action in a later post but that's all for now. Thanks!
Resources:
AI and Games retrospective with Dr. Jeff Orkin: https://www.youtube.com/watch?v=3Of2NtTYcvU














