Cameras
A CameraComponent says where the view is and how it projects. The camera rigs are small components that move that camera for you: a free-fly camera, a first-person camera, an orbit camera that circles a point, and a follow camera that trails a node. They come from the brick org.mass4.turian.cameras, in the Turian.Cameras namespace.
The rigs are in Add Component → Rendering → Camera, each under its own entry: Free Fly, FPS, Orbit and Follow. Every rig requires a CameraComponent on the same node and allows only one per node. The camera itself is configured as described in Rendering.
New projects do not include the brick. Add it with turian-cli brick add org.mass4.turian.cameras or from Project → Bricks… in Studio, then add using Turian.Cameras; to the scripts that use the rigs.
Free-fly and first-person
FreeFlyCameraComponent moves the camera along its own axes: input X moves it right, Y up, and Z forward. Its Speed is in world units per second, and LookSensitivity is in radians per mouse pixel. Call Move(Vector3 input, float deltaTime) and Look(float dxPixels, float dyPixels) from your script. Movement is not limited to the ground.
FpsCameraComponent has the same Speed, LookSensitivity, Move and Look, but it keeps forward and strafing on the ground plane, so looking up or down does not make the camera climb. Its CaptureInput property (on by default) reads WASD, Space and Left Shift for movement and right-drag for looking from the session's input source, so the rig works without any script. Set CaptureInput to false to drive Move and Look yourself.
Orbit
OrbitCameraComponent keeps the camera at Distance from a centre point and looks at it. The centre is Target, a world-space point, unless TargetNode is set. When TargetNode is set, the centre is that node's world position plus Target, so Target becomes an offset from the node. The camera is re-positioned in OnLateUpdate, so it follows a moving node without extra code.
| Member | Meaning |
|---|---|
Target |
The orbit centre, or an offset from TargetNode. |
TargetNode |
An optional node to orbit. |
Distance |
The distance from the centre. Never less than 0.01. Default 5. |
LookSensitivity |
Radians per mouse pixel. Default 0.005. |
ZoomStep |
How much Distance changes per scroll unit. Default 0.5. |
Orbit(dxPixels, dyPixels) |
Turns the camera by mouse deltas. |
Zoom(scrollDelta) |
Changes Distance by a scroll amount times ZoomStep. Positive values move the camera closer. |
If TargetNode is destroyed, the camera stops moving where it is until you clear or replace the target.
This script orbits the camera with the right mouse button and zooms with the wheel. Put it on the same node as the OrbitCameraComponent:
namespace Usercode;
using Turian.Cameras;
public sealed class OrbitControls : Component
{
[InjectService(Optional = true), JsonIgnore]
public IInputSource? Input { get; private set; }
public override void OnUpdate(float deltaTime)
{
var orbit = Node!.GetComponent<OrbitCameraComponent>();
if (orbit is null || Input is null)
{
return;
}
if (Input.IsMouseButtonDown(MouseButton.Right))
{
orbit.Orbit(Input.MouseDelta.X, Input.MouseDelta.Y);
}
orbit.Zoom(Input.MouseScrollDelta);
}
}
The Input property is the same injected input source the examples use for player input. It is null in a headless host, so the script does nothing there.
Follow
FollowCameraComponent keeps the camera at a world-space Offset from a Target node. Assign the node in the Inspector; it is required, and when it is empty or destroyed the camera stays where it is.
| Member | Default | Meaning |
|---|---|---|
Target |
none | The node to follow. |
Offset |
(0, 2, -5) |
The world-space offset from the target's position. |
PositionDamping |
0 |
The response time, in seconds, of the position. Zero snaps to the target. |
FollowRotation |
false |
Whether the camera also copies the target's world orientation. |
RotationDamping |
0 |
The response time, in seconds, of the rotation. Zero snaps when FollowRotation is on. |
Damping is exponential: after one response time, about 63 percent of the remaining distance has been covered, whatever the frame rate. The follow runs in OnLateUpdate, after the target has moved for the frame.
The quickest way to use it:
- Add a camera node with a Camera and a Follow component (Add Component → Rendering → Camera → Follow).
- Drop the player's node on the Target field.
- Set
PositionDampingto0.2for a soft lag, or leave it at0to stay locked on the target.
Camera background colour
The frame is cleared to the Background Color of the camera that renders it before the scene is drawn. It is a property of CameraComponent in the engine itself, not of the rigs, so every camera has it. The default is a cornflower blue, (0.39, 0.58, 0.93). Change it in the Inspector, or from a script:
var camera = Node!.GetComponent<CameraComponent>();
if (camera is not null)
{
camera.BackgroundColor = Color.Black;
}
It is the same Color type as the tints on other components, so Color.Black, Color.Navy and the other named colours work too. Which camera wins when several are active is decided by Priority, as described in Rendering.
Gotchas
- Each rig works on the
CameraComponentof its own node. Adding a rig also adds aCameraComponentto the node when it has none. OrbitandZoomtake mouse pixels and scroll units, not angles or world distances. Multiply your own values byLookSensitivityorZoomStepif you need a fixed speed.
Next steps
- Rendering — the camera's projection settings, lights and the frame.
- Components — the lifecycle callbacks the rigs use, and how to write your own.
- Bricks — how bricks like this one are installed and versioned.