- Documentation
- Client functions
- attachCameraRender
Function
attachCameraRender
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
detachCameraRenderDetaches the camera from an element; it stays at the spot of the last shot.setCameraRenderMirroredMirrors the camera image horizontally (a mirror). Also applies to recordings from this camera.setCameraRenderElementHiddenHides an element only in this camera's image, e.g. your own car in the mirror or the player holding a phone. The element's shadow stays. Up to 64 elements per camera.