Camera (tm.camera)
Client side only. Scripted cameras, managed by id, plus a screen filter helper.
lua
local cam = tm.camera.create({
coords = vec3(200.0, 300.0, 50.0),
rotation = vec3(-20.0, 0.0, 180.0), -- pitch, roll, yaw
fov = 50.0,
})
tm.camera.activate(cam.id)
Wait(5000)
tm.camera.deactivate(cam.id)
tm.camera.remove(cam.id)Functions
| Call | Description |
|---|---|
tm.camera.create(data) | Creates a camera and returns the camera object (it has an id). Pass active = true to start rendering from it at once. |
tm.camera.get(id) | The camera object, or nil. |
tm.camera.activate(id) | Render from this camera. |
tm.camera.deactivate(id) | Return to the gameplay camera. |
tm.camera.remove(id) | Destroy the camera. |
tm.camera.removeAll() | Destroy every camera this resource created and return to the gameplay camera. |
tm.camera.setFilter(modifier, strength?) | Apply a timecycle modifier (default strength 1.0) and flag it on LocalPlayer.state.tmScreenFilter, so scripts that clear the timecycle on a timer (pain or damage overlays) can skip it. |
tm.camera.clearFilter() | Remove the filter set with setFilter. |
Camera data
| Field | Description |
|---|---|
type | Camera type, default 'DEFAULT_SCRIPTED_CAMERA'. |
coords | vector3 position. |
rotation | vector3 pitch, roll, yaw in degrees. |
rotationOrder | Rotation order, default 2. |
fov | Field of view. |
lookAt | A position (vector3) or an entity handle to point the camera at. |
shake | { type?, amount? }, default type 'HAND_SHAKE' and amount 1.0. Starts when the camera is activated. |
onUpdate | fun(self) called every frame while the camera is active. |
active | Activate right after creating. |
Camera object
| Field or method | Description |
|---|---|
id, handle, isActive | Registry id, native handle and whether it is rendering. |
cam:activate() / cam:deactivate() | Same as the functions above. |
cam:remove() | Destroys the camera and unregisters it. Safe to call more than once. |
cam:update(data?) | Applies the camera's fields to the native camera. With a table, those fields are changed first (only the keys you give). |
The fields are plain fields, so cam.coords = newCoords moves an active camera on the next frame.
Behavior
- While at least one camera is active, one thread runs every frame and applies fields that changed. Natives only run for changed fields, plus a full re-apply once a second. With no active camera there is no thread at all.
- A camera destroyed by something else is dropped by that thread, which then ends.
- Cameras are destroyed when the resource stops.