[HELP] Creating a Custom Camera View in FiveM

Hmm…do you mean to try to take a player’s camera away from them and render it to show some random point / entity on the map? Perhaps as a backdrop for an overlay?

If so, I’m working on something similar and there’s a few things to keep in mind:

  1. Rendering / focus; - This determines what the camera is looking at. If memory serves, all activity happens around the player, and the camera is focused on the player so it looks like the camera is focused on all activity. Your goal is to simulate this process with a static set of coordinates

  2. Camera Creation - This means you have to activate your camera! There’s a native for doing just that

  3. Activating camera - And yes, it must be set as active

  4. Undoing your work when done when finished, e.g. timer runs out or you press a key, or get a signal from the server, you’ll want to undo your work, so saving the previous values are essential!

Anyways, here’s a snippet of something similar that I use:

  --"notice by this point the camera's already blacked out on the client's screen"
local camera = CreateCam("DEFAULT_SCRIPTED_CAMERA", true) --"Notice how all values point back to this value (aka handle).  This is what we reference in the rest of the script"
SetCamCoord(camera, vector3(Some, Vector, 3)) --"change the 'vector3' section"
SetCamRot(camera, vector3(rotation, vector, 3), 2) --"Change the 'vector3' section - Also, see the native and experiment with values to understand what it does"
ShakeCam(camera, "HAND_SHAKE" , 0.05) --"Not needed, but a nice touch"
RenderScriptCams(true, false, 0, true, true) 
SetFocusPosAndVel(GetCamCoord(camera), 0.0, 0.0, 0.0) --"Takes rendering away from the player and places it on the coordinate set"
SetCamActive(camera, true) "Shifts camera away to the built camera"
DisplayRadar(false) --"Disables radar"
ExecuteCommand('togglechat') --"Disables chat"
DoScreenFadeIn(3000)

Now for the undo;

DestroyCam(camera, false) 
RenderScriptCams(false, false, 0, true, true)
ClearFocus() --brings focus back to default
DisplayRadar(true)

Now comes the fun part - experiment, play with various values, etc, etc…good luck, and have fun!

If you plan on rendering a menu, you’ll either need to work with scale form (manual rendering / drawing of menus) or NUI

scaleform is harder to learn, but allows you muuch more customizability, and NUI is easier, but is limited in the options you have…

1 Like