Code
Create a new scene
Create a new GameObject called
Goap, add theGoapRunnerBehaviourto it.

Create a class called
WanderTargetthat extendsTargetKeyBase.
using CrashKonijn.Goap.Behaviours;
public class WanderTarget : TargetKeyBase
{
}Create a class called
IsWanderingthat extendsWorldKeyBase.
using CrashKonijn.Goap.Behaviours;
public class IsWandering : WorldKeyBase
{
}Create a class called
GoapSetConfigFactorythat extendsGoapSetConfigFactoryBaseand override theCreatemethod.
using CrashKonijn.Goap.Behaviours;
using CrashKonijn.Goap.Classes.Builders;
using CrashKonijn.Goap.Configs.Interfaces;
using CrashKonijn.Goap.Resolver;
using CrashKonijn.Goap.Enums;
public class GoapSetConfigFactory : GoapSetFactoryBase
{
public override IGoapSetConfig Create()
{
var builder = new GoapSetBuilder("GettingStartedSet");
// Goals
builder.AddGoal<WanderGoal>()
.AddCondition<IsWandering>(Comparison.GreaterThanOrEqual, 1);
// Actions
builder.AddAction<WanderAction>()
.SetTarget<WanderTarget>()
.AddEffect<IsWandering>(EffectType.Increase)
.SetBaseCost(1)
.SetInRange(0.3f);
// Target Sensors
builder.AddTargetSensor<WanderTargetSensor>()
.SetTarget<WanderTarget>();
// World Sensors
// This example doesn't have any world sensors. Look in the examples for more information on how to use them.
return builder.Build();
}
}Add the
GoapSetConfigFactoryto theGoapGameObject. Make sure to add theGoapSetConfigFactoryto theGoapRunnerBehaviour's factories property.

Create a script called
GoapSetBinder. This script will assign aGoapSetto theAgent.
using CrashKonijn.Goap.Behaviours;
using UnityEngine;
public class GoapSetBinder : MonoBehaviour {
public void Awake() {
var runner = FindObjectOfType<GoapRunnerBehaviour>();
var agent = GetComponent<AgentBehaviour>();
agent.GoapSet = runner.GetGoapSet("GettingStartedSet");
}
}Create a sphere
GameObjectcalledAgent. Add theAgentBehaviour,AgentMoveBehaviour,AgentBrainandGoapSetBinderto theGameObject.

Run the scene. The agent should move around randomly.
Last updated