Camera System¶
Guide for working with scripted cameras in FiveM, including spline cameras for smooth cinematic movements.
Spline Camera Example¶
Spline cameras allow you to create smooth camera movements through multiple waypoints (nodes).
Basic Setup¶
local testcam = nil
RegisterCommand('camtest', function()
local testcam = CreateCam("DEFAULT_SPLINE_CAMERA", false)
SetCamActive(testcam, false)
AddCamSplineNodeUsingCamera(testcam, CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", -185.0473, 6307.0806, 300.0, -90.0, 0.0, 45.0, 70.0, true, 2), 5000, 3)
AddCamSplineNodeUsingCamera(testcam, CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", -222.3541, 6306.7422, 45.0, -75.0, 0.0, 45.0, 70.0, true, 2), 15000, 3)
AddCamSplineNodeUsingCamera(testcam, CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", -242.4302, 6326.2070, 32.0, 0.0, 0.0, 45.0, 70.0, true, 2), 5000, 3)
-- Optional: Set total duration
-- SetCamSplineDuration(testcam, 5000)
SetCamActive(testcam, true)
RenderScriptCams(true, false, 3000, true, false, 0)
end, false)
RegisterCommand('camstop', function()
SetCamActive(testcam, false)
RenderScriptCams(false, false, 3000, true, false, 0) -- Stop rendering the camera
end, false)
Parameters Explained¶
CreateCamWithParams:
CreateCamWithParams(
"DEFAULT_SCRIPTED_CAMERA", -- Camera type
x, y, z, -- Position coordinates
rotX, rotY, rotZ, -- Rotation angles
fov, -- Field of view (degrees)
active, -- Start as active
rotationOrder -- Rotation order (2 = default)
)
AddCamSplineNodeUsingCamera:
AddCamSplineNodeUsingCamera(
splineCam, -- The spline camera handle
nodeCamera, -- Camera defining this node's position/rotation/FOV
duration, -- Time to reach this node (milliseconds)
smoothing -- Smoothing factor (higher = smoother, 3 recommended)
)
RenderScriptCams:
RenderScriptCams(
render, -- true to enable, false to disable
ease, -- Ease transition
easeTime, -- Transition duration (milliseconds)
lockInterp, -- Lock interpolation
unk1, -- Unknown (usually false)
unk2 -- Unknown (usually 0)
)
Simple Static Camera¶
For a basic fixed camera without spline movement:
local cam = CreateCam("DEFAULT_SCRIPTED_CAMERA", true)
SetCamCoord(cam, x, y, z)
SetCamRot(cam, rotX, rotY, rotZ, 2)
SetCamFov(cam, 50.0)
SetCamActive(cam, true)
RenderScriptCams(true, true, 1000, true, false, 0)
-- To stop:
SetCamActive(cam, false)
DestroyCam(cam, true)
RenderScriptCams(false, true, 1000, true, false, 0)
Point Camera at Entity¶
local cam = CreateCam("DEFAULT_SCRIPTED_CAMERA", true)
SetCamCoord(cam, x, y, z)
PointCamAtEntity(cam, entity, 0.0, 0.0, 0.0, true)
SetCamActive(cam, true)
RenderScriptCams(true, true, 1000, true, false, 0)
Camera Shake Effects¶
-- Add shake to camera
ShakeCam(cam, "HAND_SHAKE", intensity)
-- Stop shake
StopCamShaking(cam, true)
-- Available shake types:
-- "HAND_SHAKE", "SMALL_EXPLOSION_SHAKE", "MEDIUM_EXPLOSION_SHAKE"
-- "LARGE_EXPLOSION_SHAKE", "JOLT_SHAKE", "VIBRATE_SHAKE"
-- "ROAD_VIBRATION_SHAKE", "DRUNK_SHAKE", "SKY_DIVING_SHAKE"
Best Practices¶
-
Always Clean Up: Destroy cameras when no longer needed to prevent memory leaks
-
Store Camera Handles: Use module-level variables to track active cameras
-
Smooth Transitions: Use appropriate ease times in
RenderScriptCams() -
Test FOV Values: Start with 50-70 FOV, adjust based on desired effect
-
Disable Controls: Consider disabling player controls during cinematic sequences
Common Camera Types¶
DEFAULT_SCRIPTED_CAMERA- Standard fixed cameraDEFAULT_SPLINE_CAMERA- Smooth path camera with multiple nodesDEFAULT_ANIMATED_CAMERA- Camera with animation support
Troubleshooting¶
Camera not switching:
- Ensure SetCamActive(cam, true) is called before RenderScriptCams()
- Check that camera handle is valid with DoesCamExist(cam)
Jerky movement:
- Increase smoothing factor in AddCamSplineNodeUsingCamera() (use 3 or higher)
- Ensure sufficient duration between nodes
Camera stuck:
- Always call RenderScriptCams(false, ...) to return to normal gameplay camera
- Destroy camera handles with DestroyCam() when done