ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Client functions
  3. attachCameraRender

Function

attachCameraRender

ClientDrawing (dx)Trilogy Hub only

Attaches the camera to an element (a vehicle, a player, a ped, an object, a model object). The position and target are in metres in the element's frame (x right, y forward, z up); the target defaults to 10 m in front of the camera. A rear-view mirror is a camera at the back of the car looking backwards plus setCameraRenderMirrored.

Syntax

bool attachCameraRender(element camera, element element, float x, y, z [, float lx, ly, lz, float roll = 0, float fov = 70])

Arguments

cameraelement
The camera.
elementelement
The element.
x, y, zfloat
Position relative to the element.
lx, ly, lzfloat, optional
Target relative to the element.
rollfloat, optional = 0
Roll.
fovfloat, optional = 70
Field of view.

Returns

true on success.

Example

A rear-view mirror above the middle of the screen.

local mirror = createCameraRender(400, 120, 30)
setCameraRenderMirrored(mirror, true)
addEventHandler("onClientRender", root, function()
    local veh = getPedOccupiedVehicle(localPlayer)
    if not veh then return end
    if getCameraRenderAttachedTo(mirror) ~= veh then
        attachCameraRender(mirror, veh, 0, -2.5, 1, 0, -12, 0.5, 0, 60)
        setCameraRenderElementHidden(mirror, veh, true)
    end
    local sw = guiGetScreenSize()
    dxDrawImage(sw / 2 - 200, 20, 400, 120, mirror)
end)

See also