Skip to content

Camera Manager

Zay Arriaga edited this page Jun 23, 2026 · 16 revisions

System Summary

The Camera System controls how the game camera behaves in both Editor Mode (EDIT) and Play Mode (PLAY) using a single Camera2D node.

It supports:

  • Free camera movement in editor mode (WASD + panning)
  • Smooth player-follow camera in play mode
  • Zoom in/out using mouse wheel or + and - key
  • Level boundary clamping based on world size
  • State switching through a global game state system

This system replaces multiple camera controllers with a single unified state-based camera.

Connected Systems

Related Controls

Editor Mode

  • WASD or arrow keys → Move camera
  • Mouse wheel or + and - keys → Zoom in/out
  • Middle mouse button and dragging moves

Play Mode

  • Camera follows player automatically
  • No manual input

Feature List

  • Zoom system with limits
  • Tilemap boundary clamp
  • Automatic tilemap-centering on start

Important Variables

Name the most important variables, their type, and what their purpose is

  • roamCellCount: float = An exported variable that determines how far a user can pan away from the level scene before being clamped.

  • moveSpeed: float = An exported variable that determines how fast a user can move around the level scene when using WASD.

  • isPanning: bool = Whether the user is in the middle of panning the camera.

  • panSpeed: float = How fast the user can pan the screen via middle mouse button click.

  • zoomSpeed: float = An exported variable that determines how fast a user can zoom in or out the camera.

  • maxZoomOut: float = An exported variable that determines how far a user can zoom out.

  • maxZoomIn: float = An exported variable that determines how close a user can zoom in.

  • playZoom: float = An exported variable that determines how zoomed a camera is on the player.

  • gridLines: TileMapLayer = An exported variable for the grid lines tile map.

  • levelBounds: Rect2 = The absolute level bounds so that the camera cannot zoom out too much.

  • roamBounds: float = The absolute roam bounds so that the camera cannot drag too far out.

  • playerReference: CharacterBody2D = The retrieved reference to the player.

  • maxPlayerSearchAttempts: int = The max amount of times the player will be searched for.

Important Functions

Name of the most important functions, their parameters, and what they do.

  • func reset_camera() -> void: Resets the camera, and the player reference so that it has to be searched for again.

  • func refresh_bounds() -> void: Adjusts camera bounds to current grid size.

  • func try_find_player(delta: float) -> void: Searches for the first node in the "Player" group, which will be our player reference. Will only search up to maxPlayerSearchAttempts.

  • func _input() -> void: Handles middle mouse button inputs, and camera "sprinting" (panning faster while holding shift).

  • func process_build_camera(delta: float) -> void: Processes editor camera movement based on delta time.

  • func process_edge_scrolling(delta: time) -> void: Processes edge scrolling movement with the editor camera based on delta time.

  • func process_zoom(zoomAmount: float) -> void: Processes zooming based on the mouse position, and zooms in or out by the zoomAmount.

  • func process_zoom_input() -> void: Processes the zoom input, and calls the process_zoom function based on the input given by the user.

  • func process_player_camera() -> void: Follows the player, so long as there is a reference to it.

  • func get_camera_bounds() -> Rect2: Converts the roam cell count to workable pixels, and returns it to the roamBounds.

  • func clamp_camera_to_level() -> void: Prevents the camera from leaving the level outside of the roam/level bounds.

  • func camera_encloses_roam(roamingBounds: Rect2) -> bool: Returns if the camera fully encloses the level bounds as a rect.

  • func get_camera_rect() -> Rect2: Returns the camera rect

  • func get_min_zoom_to_fit_roam() -> float: Returns the minimum zoom to fit the roaming area.


Future Work / Risks (Global)

List and description of upcoming work/risks.

Future Work:

  1. Adding setting toggles for certain camera movements, such as edge pan.

Risks:

  • No known risks.

Miscellaneous Notes

  • System is single-node for simplicity
  • State switching is handled externally by MasterManager
  • Camera assumes a rectangular tilemap level world
  • Code follows modular function separation for readability
  • Edge scrolling has been removed

Clone this wiki locally