# attachCameraToElement (Client)

> Attaches the camera to an element: it follows the element's position and rotation until `setCameraTarget` gives it back to a ped.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Client
- **Category**: Camera
- **URL**: https://wiki.mymp.gg/en/attachCameraToElement

## Syntax

```lua
bool attachCameraToElement(element element, float offsetX, offsetY, offsetZ [, vec3|element lookAt = nil, float roll = 0, float fov = 70])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `element` | `element` | The element that carries the camera. |
| `offsetX, offsetY, offsetZ` | `float` | Where the camera stands, relative to the element. `0, 0, 0` becomes 2 m above it. A `vec3` also works. |
| `lookAt` | `vec3\|element` | Where it looks: a point relative to the element, as a vector, or another element to follow. Without it, it looks at the element itself. *(default: `nil`)* |
| `roll` | `float` | The sideways tilt, in degrees. *(default: `0`)* |
| `fov` | `float` | The field of view in degrees. 0 or less becomes 70; 180 or more becomes 179. *(default: `70`)* |

## Returns

`true` once the camera is attached. `false` if the element or the target is not loaded.

If the element stops existing, the camera goes back to the player.

## Example

```lua
local vehicle = getPedOccupiedVehicle(localPlayer)
if vehicle then
    attachCameraToElement(vehicle, 0, -6, 2, vec3(0, 4, 0.5))
end
```

### Note

The point to look at must be a vector (`vec3(x, y, z)`); three loose numbers are refused with a warning.

## See also

- [setCameraTarget (Client)](https://wiki.mymp.gg/en/setCameraTarget.md): Makes the camera follow a player or ped, as in normal play. It also undoes setCameraMatrix and attachCameraToElement.
- [setCameraMatrix (Client)](https://wiki.mymp.gg/en/setCameraMatrix.md): Fixes the camera at a point, looking at another, until setCameraTarget gives it back to a ped.
- [getCameraMatrix (Client)](https://wiki.mymp.gg/en/getCameraMatrix.md): Returns where the camera is and where it looks.
