Skip to main content

Strafer

Overview

The Strafer component handles the logic for strafing movement—managing when an entity begins or stops strafing, computing the target facing direction from input (keyboard or controller), and updating the Locomotor component accordingly. It supports both server-side authoritative behavior (on mastersim) and client-side prediction (on non-mastersim), and coordinates with the RPC system to synchronize direction updates across network peers.

Dependencies & Tags

  • Components Required: playercontroller, locomotor (optional, used for non-mastersim clients)
  • Events Listened To: startstrafing, stopstrafing
  • Tags Used: busy (checked via self.inst.sg:HasStateTag("busy"))

Properties

PropertyTypeDefault ValueDescription
instEntityReference to the entity this component is attached to.
ismastersimbooleanTheWorld.ismastersimIndicates whether this instance is the authoritative simulation.
playercontrollerComponent?inst.components.playercontrollerReference to the playercontroller component (may be nil on non-player entities).
aimingbooleanfalseTracks whether the entity is currently aiming/strafering.
lastdirnumber?nilStores the last known facing direction (in degrees) to avoid redundant RPCs.

Main Functions

Strafer:IsAiming()

  • Description: Returns whether the entity is currently in strafing/aiming state.
  • Parameters: None
  • Returns: booleantrue if strafing is active, otherwise false.

Strafer:OnRemoveFromEntity()

  • Description: Cleanup logic when the component is removed from the entity. Stops listening for events and ensures strafing mode is disabled on the locomotor (if applicable).
  • Parameters: None

Strafer:OnUpdate(dt)

  • Description: Computes and applies the current strafing direction every frame while aiming is true. Checks input sources (keyboard or controller), calculates direction relative to camera or world space, and updates the locomotor (if present). On non-mastersim, sends direction updates to the server via RPC. Aborts if input is disabled or the entity is in a "busy" state.
  • Parameters:
    • dt (number) — Delta time since the last update.

Events & Listeners

  • Listens for "startstrafing" → triggers OnStartStrafing
  • Listens for "stopstrafing" → triggers OnStopStrafing
  • On instantiation, checks inst.player_classified.isstrafing:value() and resumes strafing if true.