Logic¶
A GOAP AI system doesn't do anything by itself. It requires one or multiple Goals and come up with a plan to solve them and pick the most beneficial.
Setting up Goals¶
The instruction Add Goal allows to add a new one to a specific Processor component and Action Plan.
Specify Action Plan
The Action Plan asset must be specified because the AI system might contain multiple Action Plan assets running as sub graphs.
The Name field determines the Belief that will be required to satisfy (meaning it evaluates to True) in order to consider the Goal as completed.
The Weight is a value that is multiplied to the total cost when coming up with a plan that resolves this goal. This allows to prioritize some goals higher than others.
Goal Priorities
Let's say we have two goals: Stay-Alive
and Kill-Enemies
and the AI system comes up with a plan for each with the following total costs:
Stay-Alive
with a total Cost of 5Kill-Enemies
with a total Cost of 3
In this case, because killing enemies has a lower cost, it would be picked up over staying alive. However this doesn't make sense, because a character should focus on self-preservation first.
In this case, we can give the Stay-Alive
goal a Weight of 0.5, which is a coefficient that multiplies the total cost by this value, yielding the following new results:
Stay-Alive
with a total Cost of (5 * 0.5) = 2.5Kill-Enemies
with a total Cost of (3 * 1) = 3
Now staying alive will be prioritized unless killing an enemy comes at a very small cost. Note that we could have also doubled the weight of the killing enemies goal instead and it would result still work.
Just like adding goals, to remove a Goal use the Remove Goal instruction.
Planning¶
Once an Action Plan has one or more Goals it can come up with a plan, which is only done if there's not an ongoing plan being executed.
The GOAP algorithm starts coming up with a plan for each Goal, and if there are multiple plans for the same goal, stores the one with the lowest cost.
Once it has zero or one plan for each Goal it multiplies each one by their Weight value and picks the one with the lowest cost. After than it starts executing the chosen plan until it finishes or is aborted by a Condition.