Skip to main content

Distancetracker

Based on game build 714014 | Last updated: 2026-03-03

Overview

DistanceTracker is a lightweight component that records and computes the distance an entity moves per frame. It is attached to an entity and updates continuously via the OnUpdate callback, storing the entity's previous position to calculate incremental travel distance. It is primarily used for telemetry, statistics, or gameplay logic that depends on movement distance.

Usage example

local inst = CreateEntity()
inst:AddComponent("distancetracker")
-- The component automatically begins tracking distance every frame.
-- No further interaction is typically required.

Dependencies & tags

Components used: None identified
Tags: None identified

Properties

PropertyTypeDefault ValueDescription
previous_posPoint (or nil)nilStores the last known world position of the entity (in Point format) for delta calculation.
instEntityReference to the entity the component is attached to.

Main functions

OnUpdate(dt)

  • Description: Called each frame to compute the Euclidean distance traveled since the last update. Updates previous_pos with the current position.
  • Parameters: dt (number) — delta time since last frame.
  • Returns: Nothing.
  • Error states: If previous_pos is nil (e.g., on the first update), distance is recorded as 0.

Events & listeners

None identified.