Skip to main content

Stretcher

Overview

This component continuously adjusts the scale and orientation of its owner entity to visually stretch toward a specified target entity. It is typically used for visual effects such as elastic connections or body elongation in gameplay mechanics.

Dependencies & Tags

  • Relies on the entity having Transform, AnimState, and Update components.
  • Calls inst:StartUpdatingComponent(self) and inst:StopUpdatingComponent(self), indicating it integrates with the entity’s update loop.

Properties

PropertyTypeDefault ValueDescription
instEntityReference to the entity this component belongs to (set in constructor).
targetEntity?nilThe entity to stretch toward; may be nil.
restinglengthnumber1Target distance used to determine natural (non-stretched) length for scaling.
widthrationumber1Controls how much the width scales relative to length scaling.

Main Functions

SetRestingLength(length)

  • Description: Sets the resting length used as the baseline for computing stretch scale.
  • Parameters:
    • length (number): The desired resting length value.

SetWidthRatio(ratio)

  • Description: Sets the width scaling multiplier relative to the length scale change.
  • Parameters:
    • ratio (number): Scaling factor that determines how width changes as the entity stretches.

SetStretchTarget(inst)

  • Description: Assigns or clears the target entity to stretch toward. Automatically manages the update loop based on whether a target is set.
  • Parameters:
    • inst (Entity?): The target entity; if nil, disables updates.

OnEntitySleep()

  • Description: Pauses updates when the owner entity enters sleep state (e.g., off-screen or inactive).
  • Parameters: None.

OnEntityWake()

  • Description: Restarts or conditionally resumes updates when the owner entity wakes. Only updates if a valid target exists.
  • Parameters: None.

OnUpdate(dt)

  • Description: Core update logic. Adjusts scale and rotation to stretch toward the target. Stops updating if the target becomes invalid.
  • Parameters:
    • dt (number): Delta time since last frame (unused in calculations, but passed by update system).

Events & Listeners

None.