Camera System

Overview

The Camera system provides both a runtime ECS camera component and an editor fly/orbit camera. During edit mode, the editor camera controls the viewport. During play mode, the engine switches to the entity camera marked as the main camera.

Editor Camera

The editor viewport has a built-in camera with the following controls:

ActionInput
Fly modeRight-click + WASD + QE (up/down) + mouse look
SprintHold Shift during fly mode
OrbitAlt + Left-click drag
Orbit zoomAlt + Right-click drag
PanMiddle-click drag
Scroll zoomScroll wheel
Focus selectionF key (focuses on selected entity)

Adding a Camera Component

To define a runtime camera for your game:

  1. Select an entity in the Scene Hierarchy (or create a new one)
  2. In the Inspector, click Add Component > Camera
  3. Configure the camera properties
  4. Check isMain to make it the active play-mode camera

Camera Properties

FieldTypeDefaultDescription
fovfloat45.0Field of view in degrees
nearPlanefloat0.1Near clipping distance
farPlanefloat1000.0Far clipping distance
projectionTypePerspective / OrthographicPerspectiveProjection mode
orthoSizefloat10.0Orthographic view size (Orthographic only)
isMainboolfalseTag this as the active runtime camera

Runtime Camera System

When you press Play, the engine activates a CameraSystem that:

  1. Queries all entities with both Camera and Transform components
  2. Finds the entity with isMain == true
  3. Computes view and projection matrices from that entity's Transform and Camera properties
  4. Feeds those matrices to the renderer

When you press Stop, the editor camera resumes control.

Tip

If no camera has isMain == true, the viewport will show a default view during play mode. Always mark one camera as main.

Multiple Cameras

You can have multiple camera entities in a scene. Only one should have isMain = true at a time. Switch between them in code using engine.SetMainCamera():

auto cam = engine.GetWorld().lookup("CinematicCamera");
engine.SetMainCamera(cam); // clears isMain on all others, sets it on this one
MethodDescription
engine.GetMainCamera()Returns the entity with isMain == true
engine.SetMainCamera(entity)Clears isMain on all cameras, sets it on target

For detailed scripting examples, see Camera Scripting.

Frustum Gizmo

In edit mode, every camera entity displays a wireframe frustum in the viewport showing:

  • Near and far clipping planes
  • Field of view cone (or orthographic box)
  • Forward direction indicator (blue line)
  • Up direction triangle at the top

This helps you position and orient cameras in the scene without entering play mode.

Inspector Preview

When you select a camera entity in the editor, the Inspector panel shows a live preview thumbnail at the top of the Camera component. This renders the scene from the camera's perspective in real-time, updating as you adjust the Transform or camera properties.

Integration Notes

  • The editor viewport uses its own EditorCamera, completely separate from any Camera components
  • During play mode, the CameraSystem runs at PreUpdate phase, setting view/projection before the render pass
  • Camera components support both Perspective and Orthographic projection
  • The gizmo and preview are only visible in edit mode
  • Gizmo manipulation (translate/rotate/scale) is disabled during play mode