WanderAction

Agent action implementing the NPC wandering behavior loop. The agent moves between random waypoints at varying speeds, periodically visits the store area, and exits when a purchasable item is found — setting sequence variables for downstream trade actions.

Definition

Namespace: Paragon.Townskeep.AgentSystem Assembly: Townskeep.dll

public class WanderAction : AgentAction

Inheritance: ActionAgentAction → WanderAction

Remarks

WanderAction is the most complex agent action — it combines exploration, speed management, and shop interaction detection into a single behavior loop. It typically serves as the first action in a trade sequence, responsible for discovering items to buy.

Execution Flow

spinner

Waypoint System

The action expects a scene hierarchy:

Wander Waypoints (GameObject)
├── Waypoint1           ← random wander target
├── Waypoint2           ← random wander target
├── ...
├── Connection          ← hub waypoint (returned to between wanders)
└── Store               ← triggers item search when reached
  • Wander targets — all children except "Connection" and "Store"

  • Connection target — the hub waypoint; the agent always returns here between random wanders

  • Store target — when reached, the agent checks display tables for available items

Speed Management

When moving toward the store, speed adjusts based on distance:

Distance to Store
Speed Mode

< 2 units

Motor.SetWalk(true) — slow approach

< 5 units

Motor.SetWalk(false) — normal speed

≥ 5 units

Motor.SetSprint(true) — sprint

For all non-store waypoints, the agent always sprints.

Variable Outputs

When a purchasable item is found, WanderAction sets two sequence variables that downstream actions consume:

Variable
Type
Used By

Quick Lookup

Goal
How

Start wandering behavior

Add WanderAction to the beginning of an ActionSequence

Configure waypoints

Create "Wander Waypoints" GameObject with child transforms

Access found item

Read sequence.GetVariable<Item>("Item") in next action

Access found table

Read sequence.GetVariable<Table>("Table") in next action

Fields

Field
Type
Access
Description

targetTable

Table

[Variable] private

The display table with an available item (set on discovery)

currentTarget

Transform

[Variable] private

The current movement target waypoint

wanderTargets

List<Transform>

private

All non-special wander waypoints

connectionTarget

Transform

private

The "Connection" hub waypoint

storeTarget

Transform

private

The "Store" waypoint that triggers item checks

displayTables

List<Table>

private

All tables named "Display Table" in the scene

moveAction

MoveToTargetAction

private

Sub-action for NavMesh-based movement

Methods

OnBegin

Finds all "Display Table" objects, parses the "Wander Waypoints" hierarchy into categories, and creates a MoveToTargetAction.

OnExecute

Runs the wander loop: picks random waypoints, moves to them, checks for items at the store, and returns when an item is found.

MoveToWaypoint (private)

Moves to a waypoint with a random ±3 unit offset. Uses distance-based speed adjustment when targeting the store, or sprints for all other waypoints.

Parameter
Type
Description

waypoint

Transform

The waypoint to move toward

GetRandomWanderTarget (private)

Returns a random waypoint from wanderTargets.

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation
circle-exclamation
circle-exclamation
circle-exclamation
circle-exclamation

See Also

Last updated