Skip to main content

Boattrail

Overview

The Boattrail component is responsible for generating a trail of visual water wake effects as its parent entity moves. It tracks the distance traveled and periodically spawns a boat_water_fx prefab to create the illusion of a wake. The component automatically stops updating when the entity is asleep (off-screen) to conserve resources.

Dependencies & Tags

None identified.

Properties

PropertyTypeDefault ValueDescription
anim_idxnumber0A zero-based index used to cycle through the available wake animations.
effect_spawn_ratenumber1The distance the entity must travel before a new wake effect is spawned.
radiusnumber3The distance behind the entity's center where the wake effect is spawned.
scale_xnumber1The horizontal scale applied to the spawned wake effect prefab.
scale_znumber1The depth scale applied to the spawned wake effect prefab.
total_distance_travelednumber0Tracks the accumulated distance traveled since the last effect was spawned.
last_xnumbernilThe entity's X-coordinate from the previous update frame.
last_znumbernilThe entity's Z-coordinate from the previous update frame.

Main Functions

SpawnEffectPrefab(x, y, z, dir_x, dir_z)

  • Description: Spawns a single boat_water_fx prefab at a calculated position behind the entity, applies scaling, and assigns a semi-random animation to it. If the spawned prefab has a boattrailmover component, this function will configure it.
  • Parameters:
    • x, y, z: The current world coordinates of the parent entity.
    • dir_x, dir_z: The normalized direction vector of the parent entity's movement.

OnUpdate(dt)

  • Description: This function is called every frame. It calculates the distance the entity has traveled since the last update. If the accumulated distance exceeds effect_spawn_rate, it calls SpawnEffectPrefab to create a new wake effect and resets the distance counter.
  • Parameters:
    • dt: The delta time (time elapsed since the last frame).

Events & Listeners

  • entitysleep: When the parent entity goes to sleep (is off-screen), this component stops its update tick to save performance.
  • entitywake: When the parent entity wakes up (comes on-screen), this component resets its position tracking and resumes its update tick.