Last updated
Last updated
A Sensor
is a class that reads the current state of the world and provides this information to the WorldState
when it's needed. The Resolver
uses this information to determine the best action to perform based on the current state of the world.
Sensors can provide the values for two types of data/keys:
WorldKey: A WorldKey references a value in the world. For example AppleCount
. All values must be represented by ints
.
TargetKey: A TargetKey references a position in the world. For example AppleTree
. All positions must be represented by Vector3
.
Sensors can work in two scopes: Global
or Local
.
Global: These sensors give information for all agents of an AgentType
. For instance, IsDaytimeSensor
checks if it's day or night for everyone.
Local: They give information for just one agent. For example, ClosestAppleSensor
finds the nearest apple for a specific agent.
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:
IsHungrySensor
checks if the agent is hungry.
HasAppleSensor
checks if the agent has an apple.
To create a new WorldSensor
, create a new class that inherits from LocalWorldSensorBase
or GlobalWorldSensorBase
and implement its Sense
method.
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, ClosestEnemySensor
finds a moving enemy.
PositionTarget: Use this for a fixed spot. Like, WanderTargetSensor
finds a random spot that doesn't move.
To create a new TargetSensor
, create a new class that inherits from LocalTargetSensorBase
or GlobalTargetSensorBase
and implement its Sense
method.
MultiSensor
is a sensor that combines multiple sensors. It can be used to combine multiple sensors into one sensor class. This can make it easier to manage multiple values that come from the same source.
You can set a timer for a sensor to update at a specific interval. This can be useful when you want to update a sensor every few seconds instead of every frame, or when you want to update a sensor just a single time.
By default the following timers are provided, but custom implementations of ISensorTimer
can be made.
WorldKey
LocalWorldSensorBase
GlobalWorldSensorBase
TargetKey
LocalTargetSensorBase
GlobalTargetSensorBase