Sensors
Sensors help the GOAP system understand the current game situation.
There are two main types of sensors: WorldSensor and TargetSensor.
Global vs. Local Sensors
Sensors can work in two modes: Global or Local.
Global: These sensors give information for all agents. For instance,
IsDaytimeSensorchecks if it's day or night for everyone.Local: These sensors check only when the
Plannerruns. They give information for just one agent. For example,ClosestAppleSensorfinds the nearest apple for a specific agent.
WorldSensor
WorldSensor checks the game's situation for an agent. It uses WorldKey to show each situation. The Planner uses this to pick the best action.
Examples:
IsHungrySensorchecks if the agent is hungry.HasAppleSensorchecks if the agent has an apple.
Example
To create a new WorldSensor, create a new class that inherits from LocalWorldSensorBase or GlobalWorldSensorBase and implement its Sense method.
using CrashKonijn.Goap.Behaviours;
using CrashKonijn.Goap.Classes;
using CrashKonijn.Goap.Classes.References;
using CrashKonijn.Goap.Sensors;
using Demos.Shared.Behaviours;
namespace Demos.Simple.Sensors.World
{
public class IsHungrySensor : LocalWorldSensorBase
{
public override void Created()
{
}
public override void Update()
{
}
public override SenseValue Sense(IMonoAgent agent, IComponentReference references)
{
// References are cached by the agent.
var hungerBehaviour = references.GetComponent<HungerBehaviour>();
if (hungerBehaviour == null)
return false;
return hungerBehaviour.hunger > 20;
}
}
}TargetSensor
TargetSensor finds a position for a TargetKey. The Planner uses this to know how far actions are.
There are two kinds of Target: TransformTarget and PositionTarget.
TransformTarget: Use this when the target can move. For example,
ClosestEnemySensorfinds a moving enemy.PositionTarget: Use this for a fixed spot. Like,
WanderTargetSensorfinds a random spot that doesn't move.
Example
To create a new TargetSensor, create a new class that inherits from LocalTargetSensorBase or GlobalTargetSensorBase and implement its Sense method.
Last updated