MoveToTargetAction

Core movement primitive for agent AI. Sets a NavMesh destination and continuously drives the character's controller toward the next path position until within 0.5 units of the target. Used directly and as a sub-action by higher-order actions.

Definition

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

public class MoveToTargetAction : AgentAction

Inheritance: ActionAgentAction → MoveToTargetAction

Remarks

MoveToTargetAction is the fundamental movement building block for agent AI. Most other movement-based actions (GoToTradeAction, GoToStoreAction, FollowPathAction, WanderAction) create and delegate to MoveToTargetAction internally.

Movement Loop

spinner

Key Design Decisions

Decision
Rationale

navMeshAgent.SetDestination for path calculation

NavMeshAgent is configured with updatePosition = false — it calculates the path but doesn't move the transform

character.Controller.MoveTo for actual movement

The character's controller/motor handles physics and animation

Teleport guard (nextStepDistance > 1f)

If the NavMesh suggests a position more than 1 unit away, it reverts to the last known good position to prevent teleporting

Arrival threshold 0.5f

Movement loop exits when within 0.5 units of the destination

Camera follows forward direction

character.Camera.LookAt(Position + forward) keeps the camera pointing ahead during movement

Usage as Sub-Action

MoveToTargetAction is commonly created inside other actions' OnBegin() methods:

Quick Lookup

Goal
How

Move agent to a position

moveAction.SetTargetPosition(pos); await moveAction.ExecuteAsync()

Set target programmatically

moveAction.SetTargetPosition(Vector3)

Set target from Inspector

Bind targetPosition via [Variable] in the sequence

Use as sub-action

Create in OnBegin(), call Initialize(agent, sequence), then use in OnExecute()

Fields

Field
Type
Access
Description

targetPosition

Vector3

[Variable] private

The destination position; settable via Inspector, sequence variables, or SetTargetPosition()

nextPosition

Vector3

private

Last known good NavMesh position (for teleport guard)

Methods

SetTargetPosition

Sets the movement target position. Call this before Execute() or ExecuteAsync() when using programmatically.

Parameter
Type
Description

targetPosition

Vector3

World-space destination position

OnExecute

Runs the movement loop: sets NavMesh destination, drives the character controller each frame, and awaits arrival within 0.5 units.

Common Pitfalls

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

See Also

Last updated