Camera
The engine provides a camera system with two modes: third-person orbit (default) and first-person. Toggle between them with TAB.
Setup
Attach a Camera component to any entity with a Transform:
The CameraFollowSystem handles all camera logic automatically.
Player Movement Coupling
When an entity has both Camera and Movable, the InputMovementSystem uses the camera yaw to drive camera-relative movement:
W / Smove forward/back along camera-facing ground directionA / Dstrafe left/right relative to camera- The player visual
Transform.Rotation.Yis updated to face the movement direction
This gives third-person style controls where movement direction follows camera orientation.
Camera Modes
Third-Person (CameraMode.ThirdPerson, default)
The camera orbits around the entity at a configurable distance. Scroll wheel zooms in and out, clamped between MinDistance and MaxDistance.
First-Person (CameraMode.FirstPerson)
The camera is placed at the entity's position plus EyeHeight on the Y axis. It looks in the direction defined by Yaw and Pitch. Scroll wheel zoom is not used in this mode.
Switching Modes
Press TAB to toggle between modes. The toggle is edge-detected (fires once per press).
Controls
How It Works
- Orbit distance is calculated from the length of the
Offsetvector - Yaw and Pitch define the spherical coordinates around the entity
- In third-person mode, the camera position is computed as: entity position + spherical offset
- In first-person mode, the camera is at entity position +
EyeHeight, looking along the yaw/pitch direction - Pitch is clamped to [-89, 89] degrees to prevent gimbal lock
- The view matrix is set via
NativeBridge.SetCamera()
Mouse Look
When the cursor is locked (press ESC to toggle):
- Mouse movement updates
YawandPitchbased onMouseSensitivity - The cursor is hidden and captured for raw input
- Press ESC again to release the cursor
When the cursor is free, only keyboard orbit (Q/E/R/F) works.
Default Camera
If no Camera component is attached to any entity, the renderer uses its built-in default:
- Eye position:
(0, 0, 3) - Look-at target:
(0, 0, 0) - Up vector:
(0, 1, 0) - FOV: 45 degrees
Free Camera (Debug)
The engine includes a debug fly camera for inspecting the scene freely. It is only available when GameConstants.Debug is true.
Activating
When the free camera is active, player input (InputMovementSystem) is disabled — WASD controls only the free camera.
FreeCameraSystem is optional. Register world.AddSystem(Systems.FreeCameraSystem); before CameraFollowSystem to enable it.
Controls
Configuration
Sensitivity and speed are configured in GameConstants:
FOV is set in FreeCameraState.Fov (default 45).
How It Works
FreeCameraSystemruns beforeCameraFollowSystem- When active, it overrides the camera via
NativeBridge.SetCamera()directly CameraFollowSystemreturns early when the free camera is activeInputMovementSystemreturns early when the free camera is active- Pressing 1 deactivates the free camera and resets entity camera mouse state to avoid delta jumps
State
Free camera state is stored in FreeCameraState (static class, not an ECS component):