# Camera

> Controlling and reading an avatar's camera from scripts.

Each avatar has one camera, controlled by the viewer. Scripts can suggest a default view when someone sits, take over the camera with permission, or read where the camera is.

Scripts never own the camera. They ask, and the viewer applies it. Two permissions are involved: [`PERMISSION_CONTROL_CAMERA`](/constants/PERMISSION_CONTROL_CAMERA/) to set camera parameters and [`PERMISSION_TRACK_CAMERA`](/constants/PERMISSION_TRACK_CAMERA/) to read the camera position and rotation.

`PERMISSION_CONTROL_CAMERA` is automatically granted for attached or sat-on objects, so HUDs, seats and vehicles get it without a prompt.

## Concepts

- A [sit camera](#sit-camera) needs no permission
  - Set an [eye offset](/functions/llSetCameraEyeOffset/) and a [focus offset](/functions/llSetCameraAtOffset/) on the prim; the viewer uses them when an avatar [sits there](/functions/llSitTarget/)
  - [`llSetLinkCamera`](/functions/llSetLinkCamera/) does the same for any prim in the linkset
- A [scripted camera](/functions/llSetCameraParams/) takes over the view
  - Parameters set the camera position, focus, distance, lag and thresholds, and can lock either point in place
  - They stay in effect until [cleared](/functions/llClearCameraParams/)
  - Vehicles, follow cameras and cutscenes are built this way
  - A script can also [force mouselook](/functions/llForceMouselook/)
- [Reading the camera](/functions/llGetCameraPos/) needs `PERMISSION_TRACK_CAMERA`
  - [Position](/functions/llGetCameraPos/), [rotation](/functions/llGetCameraRot/), [field of view](/functions/llGetCameraFOV/) and [aspect ratio](/functions/llGetCameraAspect/)
  - For example to aim along the view or [place a HUD element](/functions/llWorldPosToHUD/) in the world
- Permissions are [requested](/functions/llRequestPermissions/) and arrive in [`run_time_permissions`](/events/run_time_permissions/)
- Camera scripts are usually paired with [control capture](/features/input/), so the user can steer while the script drives the view

## Functions and events

- `void` [`llSetCameraEyeOffset`](/functions/llSetCameraEyeOffset/) `(vector offset)`
- `void` [`llSetCameraAtOffset`](/functions/llSetCameraAtOffset/) `(vector offset)`
- `void` [`llSetLinkCamera`](/functions/llSetLinkCamera/) `(integer link, vector eye, vector at)`
- `void` [`llSetCameraParams`](/functions/llSetCameraParams/) `(list rules)`
- `void` [`llClearCameraParams`](/functions/llClearCameraParams/) `()`
- `void` [`llForceMouselook`](/functions/llForceMouselook/) `(integer mouselook)`
- `vector` [`llGetCameraPos`](/functions/llGetCameraPos/) `()`
- `rotation` [`llGetCameraRot`](/functions/llGetCameraRot/) `()`
- `float` [`llGetCameraFOV`](/functions/llGetCameraFOV/) `()`
- `float` [`llGetCameraAspect`](/functions/llGetCameraAspect/) `()`

## Sit camera

The simplest camera control: offsets stored on the prim and used by the viewer when an avatar sits on it.

## [FollowCam](https://wiki.secondlife.com/wiki/FollowCam)

A wiki page on following cameras built with [`llSetCameraParams`](/functions/llSetCameraParams/).

## Scripting Details

- `void` [`llSetCameraEyeOffset`](/functions/llSetCameraEyeOffset/) `(vector offset)`: Sets the eye offset vector (in local coordinates) where a seated avatar's camera is positioned.
- `void` [`llSetCameraAtOffset`](/functions/llSetCameraAtOffset/) `(vector offset)`: Sets the target offset vector (in local coordinates) that a seated avatar's camera will look at.
- `void` [`llSetLinkCamera`](/functions/llSetLinkCamera/) `(integer link, vector eye, vector at)`: Sets the camera eye position offset eye and looking-at position offset at for avatars who sit on the linked prim link.
- `void` [`llSitTarget`](/functions/llSitTarget/) `(vector offset, rotation rot)`: Sets the sit target position (offset) and rotation (rot) relative to the prim's position and orientation. Clears the sit target if offset is ZERO_VECTOR.
- `void` [`llSetCameraParams`](/functions/llSetCameraParams/) `(list rules)`: Sets multiple camera parameters simultaneously using the list of rules. Requires the PERMISSION_CONTROL_CAMERA runtime permission.
- `void` [`llClearCameraParams`](/functions/llClearCameraParams/) `()`: Resets all camera parameters to default values and turns off scripted camera control. Requires the PERMISSION_CONTROL_CAMERA runtime permission (automatically granted for attached or sat-on objects).
- `void` [`llForceMouselook`](/functions/llForceMouselook/) `(integer mouselook)`: Sets whether any avatar sitting on this prim is forced into mouselook mode. Setting mouselook to TRUE forces the mode; FALSE (default) allows the avatar to keep their current camera mode.
- `vector` [`llGetCameraPos`](/functions/llGetCameraPos/) `()`: Returns a vector representing the camera's current position in region coordinates of the agent who granted PERMISSION_TRACK_CAMERA. Returns ZERO_VECTOR if permissions are not granted.
- `rotation` [`llGetCameraRot`](/functions/llGetCameraRot/) `()`: Returns a rotation representing the camera's current orientation of the agent who granted PERMISSION_TRACK_CAMERA. Returns ZERO_ROTATION if permissions are not granted.
- `float` [`llGetCameraFOV`](/functions/llGetCameraFOV/) `()`: Returns a float representing the camera's current field of view (FOV) in radians of the agent who granted PERMISSION_TRACK_CAMERA. Returns 0.0 if permissions are not granted.
- `float` [`llGetCameraAspect`](/functions/llGetCameraAspect/) `()`: Returns a float representing the camera's current aspect ratio (width/height) of the agent who granted PERMISSION_TRACK_CAMERA. Returns 0.0 if permissions are not granted.
- `vector` [`llWorldPosToHUD`](/functions/llWorldPosToHUD/) `(vector world_pos)`: Returns the local position vector that places the center of the HUD object directly over the world coordinate world_pos as viewed by the current camera. Requires the PERMISSION_TRACK_CAMERA runtime permission.
- `void` [`llRequestPermissions`](/functions/llRequestPermissions/) `(key agent, integer permissions)`: Requests permissions (a bitfield specified by permissions) from the agent in the same region, calling run_time_permissions if granted. This call does not pause script execution.
- `event` [`run_time_permissions`](/events/run_time_permissions/) `(integer perm)`: Triggered when an agent grants or denies runtime permissions requested by llRequestPermissions. Passes the active integer permissions bitfield perm (returns 0 if no permissions are currently granted).

## Additional

- [`llRequestPermissions`](/functions/llRequestPermissions/) — the two camera permissions
  - [`PERMISSION_CONTROL_CAMERA`](/constants/PERMISSION_CONTROL_CAMERA/) — control the agent's camera; the agent must be sitting on or attached to the object, and it is revoked on standing up or detaching
  - [`PERMISSION_TRACK_CAMERA`](/constants/PERMISSION_TRACK_CAMERA/) — track the agent's camera position and rotation
- [`llSetCameraParams`](/functions/llSetCameraParams/) — rules list of camera parameters
  - [`CAMERA_ACTIVE`](/constants/CAMERA_ACTIVE/) — turns scripted control of the camera on or off
  - [`CAMERA_POSITION`](/constants/CAMERA_POSITION/) and [`CAMERA_FOCUS`](/constants/CAMERA_FOCUS/) — camera position and focus in region coordinates
  - [`CAMERA_POSITION_LOCKED`](/constants/CAMERA_POSITION_LOCKED/) and [`CAMERA_FOCUS_LOCKED`](/constants/CAMERA_FOCUS_LOCKED/) — lock either point so it does not move
  - [`CAMERA_DISTANCE`](/constants/CAMERA_DISTANCE/) — how far away the camera wants to be from its target
  - [`CAMERA_PITCH`](/constants/CAMERA_PITCH/) — aim straight ahead versus straight down, at the same distance
  - [`CAMERA_FOCUS_OFFSET`](/constants/CAMERA_FOCUS_OFFSET/) — focus position relative to the target
  - [`CAMERA_BEHINDNESS_ANGLE`](/constants/CAMERA_BEHINDNESS_ANGLE/) and [`CAMERA_BEHINDNESS_LAG`](/constants/CAMERA_BEHINDNESS_LAG/) — how the camera follows changes in target rotation
  - [`CAMERA_POSITION_LAG`](/constants/CAMERA_POSITION_LAG/) and [`CAMERA_FOCUS_LAG`](/constants/CAMERA_FOCUS_LAG/) — how much the camera lags as it moves and aims
  - [`CAMERA_POSITION_THRESHOLD`](/constants/CAMERA_POSITION_THRESHOLD/) and [`CAMERA_FOCUS_THRESHOLD`](/constants/CAMERA_FOCUS_THRESHOLD/) — spheres within which target motion is ignored

## Reference

Constant groups: [CameraParam](/constants/groups/CameraParam/) (14), [ScriptPermission](/constants/groups/ScriptPermission/) (13)

## Related

See also: [Input](/features/input/), [Avatars](/features/avatar/), [Camera](/categories/camera/), [LSL Camera (Second Life Wiki)](https://wiki.secondlife.com/wiki/Category:LSL_Camera), [FollowCam (Second Life Wiki)](https://wiki.secondlife.com/wiki/FollowCam)

## Related features

- [Avatars](/features/avatar/)
- [Input](/features/input/)
- [Movement](/features/movement/)

## Categories

- [Camera](/categories/camera/)

---

From lsl.dev: https://lsl.dev/features/camera/
