Another amazing feature with GOAP is the ability to dynamically decide at runtime, which set of action is more worth taking for the agent.
So if you want your agent to appear 3 dimensional, definitely consider where you can use dynamic cost.
An example may be is you have a pick up action and the closer you are, the less it cost. This will essentially sets it up so if you are too far, you won't even bother.
In order to use dynamic cost, there are three possible ways
Overriding DynamicallyEvaluateCost
public class PickUpAction : Action
{
public override void DynamicallyEvaluateCost()
{
Cost = DistanceToItem;
}
}
Overriding DynamicallyEvaluateCost(Dictionary<string, float> currentState)
This override is only necessary if you want to calculate cost based on the planner's state of calculation. That is the current state. Honestly, this is overkill and I don't often recommend using it unless you have a reason to.
public override float DynamicallyEvaluateCost(Dictionary<string, float> currentState)
{
return DistanceToItem > 2 ? 1 : 100;
}
Using the CostEvaluators
Inherit from CostsEvaluator, if you inherit from BasicCostEvaluator, you'll get access to BasicAgentData.
The context here is allows you to cast to your specific needs.
public class PickUpCostEvaluator: CostEvaluator
{
public override float Evaluate(IContext context)
{
var specialContext = context.Get<SpecialContext>();
return DistanceToItem > 2 ? 1 : 100;
}
}