Skip to main content

Distancetracker

Overview

This component attaches to an entity and continuously tracks the distance it travels. It stores the entity's position from the previous game frame and uses it to calculate the displacement in the current frame, effectively measuring movement over time.

Dependencies & Tags

None identified.

Properties

PropertyTypeDefault ValueDescription
previous_posVector3nilThe Point (Vector3) representing the entity's world position from the immediately preceding update frame.

Main Functions

OnUpdate(dt)

  • Description: This function is called every game frame the component is active. It retrieves the entity's current position, calculates the distance traveled since the last OnUpdate call using the stored previous_pos, and then updates previous_pos to the current location for the next frame's calculation. The commented-out code indicates a historical intention to send game statistics related to distance traveled.
  • Parameters:
    • dt: (number) The time elapsed in seconds since the last frame.