Skip to content

FollowEntityTask ​

Inherits: BehaviorTask < Resource

Follow an entity by unique ID with proper validation and error handling. Uses ObjectRegistry to find the target entity and fails gracefully if not found.

Properties ​

inttarget_entity_id0
floatfollow_distance3.0
floatmax_follow_distance10.0
booluse_formation_positionfalse
boolforce_walkingfalse
floatcatch_up_threshold15.0
floatstop_following_distance1.5
floatupdate_interval0.5

Variables ​

Timerfollow_timernull
Entitytarget_entitynull
Vector3last_target_positionVector3.ZERO
boolis_followingfalse
floatlast_validation_check0.0
floatvalidation_interval5.0

Methods ​

voidexecute_task_start()
voidexecute_task_complete()
voidexecute_task_interrupt()
voidexecute_task_fail()
Entityget_target_entity()
voidset_target_entity_id( new_id: int )
floatget_distance_to_target()
voidcleanup_timers()

Property descriptions ​

Follow Settings

int target_entity_id = 0 ​

Unique entity ID of the target to follow

float follow_distance = 3.0 ​

Distance to maintain from target

float max_follow_distance = 10.0 ​

Maximum distance before moving closer

bool use_formation_position = false ​

Whether to use formation positioning (for pets)

bool force_walking = false ​

Force walking even when far from target

Behavior

float catch_up_threshold = 15.0 ​

Distance at which to teleport to target (catch-up)

float stop_following_distance = 1.5 ​

Distance at which to stop moving closer

float update_interval = 0.5 ​

How often to update follow position (seconds)

Variable descriptions ​

Timer follow_timer = null ​

The timer that checks the followed entity.

Entity target_entity = null ​

The entity being followed.

Vector3 last_target_position = Vector3.ZERO ​

Where the followed entity was on the last check.

bool is_following = false ​

True while the entity follows.

float last_validation_check = 0.0 ​

The time of the last check that the followed entity is still there.

float validation_interval = 5.0 ​

Check target validity every 5 seconds

Method descriptions ​

void execute_task_start() ​

Starts the task.

void execute_task_complete() ​

Called when the task finishes well.

void execute_task_interrupt() ​

Called when something interrupts the task.

void execute_task_fail() ​

Called when the task fails.

Entity get_target_entity() ​

Get the current target entity (for external access)

void set_target_entity_id( new_id: int ) ​

Change the target entity ID (will re-validate on next update)

float get_distance_to_target() ​

Get current distance to target

void cleanup_timers() ​

Frees the timers of the task.