Skip to main content

Walkableplatformplayer

Overview

This component handles player-specific behavior when riding or standing on a walkable platform (e.g., a boat). It manages platform entry/exit, movement prediction, camera control (including smooth follow and dynamic zoom), and periodic music triggers based on platform speed. It operates under the assumption that the parent entity is a player and integrates closely with the walkableplatform component and camera subsystems.

Dependencies & Tags

  • Component Dependencies:
    • inst.Transform:SetIsOnPlatform(bool) — relies on transform support for platform state.
    • TheFocalPoint.components.focalpoint — uses focal point system for camera focus.
    • platform.components.walkableplatform — accesses platform methods such as AddPlayerOnPlatform, RemovePlayerOnPlatform, HasPlatformCamera, SpawnPlayerCollision, and DespawnPlayerCollision.
  • Tags Added/Removed: None explicitly added or removed by this component.
  • Network Scope: Uses TheNet:IsDedicated() and TheWorld.ismastersim to differentiate client and server behavior.

Properties

PropertyTypeDefault ValueDescription
instEntityReference to the owning player entity.
platformEntity?nilCurrent walkable platform the player is on.
boat_camera_enabledbooleanfalseControls whether boat-specific camera behavior is active.
player_zoomed_outbooleanfalseIndicates if zoom-out is currently applied. (Note: Not directly written, but player_zoomout is used in zoom logic.)
player_zoomsnumberNUM_ZOOMS (20)Counter tracking number of zoom steps applied.
player_zoom_taskDoTaskInTime?nilPeriodic task for progressive zoom steps.
player_zoomoutbooleanfalseRequested zoom-out state (set via "doplatformcamerazoomdirty" event).
test_boat_speed_taskDoTaskInTime?nilPeriodic task for boat speed monitoring (used to trigger music).
boatposVector3?nilCached last platform position for speed calculation.
boatspeednumber?nilCached squared platform speed (previous frame).
movement_prediction_enabledbooleanfalseControls whether movement prediction and collision is active.
_doplatformcamerazoomdirtyfunctionListener callback for platform camera zoom state changes.

Main Functions

StartBoatMusicTest()

  • Description: Starts a periodic task (every 0.5s) to monitor platform speed and trigger "playboatmusic" event when the platform exceeds the speed threshold (BOAT_SPEED_MUSIC_THRESHOLD = 0.2). Only runs on the client (TheNet:IsDedicated() check is in higher-level callers).
  • Parameters: None.

StopBoatMusicTest()

  • Description: Cancels the speed-monitoring task and clears position caches (boatpos, test_boat_speed_task).

StartBoatCamera()

  • Description: Registers the platform as a focus source for the camera with custom update/active functions (BoatCam_UpdateFn, BoatCam_ActiveFn). Enables smooth camera following and dynamic pan gain based on platform velocity.
  • Parameters: None.

StopBoatCamera()

  • Description: Removes the platform from the camera focal point system, stopping custom boat camera behavior.

StartBoatCameraZooms()

  • Description: Begins listening for "doplatformcamerazoomdirty" events from the platform and initiates zoom progression if doplatformcamerazoom is active. Launches a periodic task (player_zoom) that emits "zoomcamera" events to gradually zoom out/in.

StopBoatCameraZooms()

  • Description: Stops listening for "doplatformcamerazoomdirty" events. Cancels zoom task and ensures final zoom state is reset if needed.

GetOnPlatform(platform)

  • Description: Handles logic when the player lands on or moves onto a walkable platform. Sets platform state on transform, adds player to platform’s list, spawns collision if prediction is enabled, and conditionally starts camera/zoom/music on client.
  • Parameters:
    • platform (Entity) — The walkable platform entity being entered.

GetOffPlatform()

  • Description: Handles cleanup when leaving a platform: stops camera/zoom/music on client, removes player from platform’s list, despawns collision if prediction was enabled, and clears platform state.

TestForPlatform()

  • Description: Reevaluates which platform (if any) the player is standing on. Triggers GetOffPlatform() and GetOnPlatform() as needed. Runs differently on master (TheWorld.ismastersim) vs. client (determines platform via TheWorld.Map:GetPlatformAtPoint).
  • Parameters: None.

OnRemoveEntity()

  • Description: Cleans up platform state upon entity removal (e.g., player logout/death), ensuringfollowership and player count are correctly decremented and transform state cleared.

Events & Listeners

  • Listens For:
    • "enableboatcamera" → calls EnableBoatCamera(inst, enabled)
    • "enablemovementprediction" → calls EnableMovementPrediction(inst, enabled)
    • "playeractivated" → triggers delayed DoStartBoatCamera
    • "doplatformcamerazoomdirty" (on platform) → triggers OnDoPlatformCameraZoomDirty
  • Emits:
    • "playboatmusic" — when platform speed crosses threshold.
    • "got_on_platform", platform — upon entering a platform (client only).
    • "got_off_platform", platform — upon exiting a platform (client only).
    • "zoomcamera", {zoomout = bool, zoom = step} — during zoom progression.

Note: Event emitters EnableBoatCamera, EnableMovementPrediction, and DoStartBoatCamera are helper functions (not part of the class itself), but the component registers them as event listeners.