Creating Camera

Hello everyone I am currently working on a script and I have a problem where I need to create a camera and I tried using this code:

function DeathCam()
  local PlayerPed = PlayerPedId()
  local pos = GetEntityCoords(PlayerPed)
  local heading = GetEntityHeading(PlayerPed)
  cam = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", pos.x, pos.y + 0.5, pos.z + 0.5, 0.0 ,0.0, heading, 60.00, false, 0)
  SetCamActive(cam, true)
  FreezeEntityPosition(PlayerPed, false)
  print("displaying cam")
end

It is printing the “displaying cam” but its just not showing the camera.
If someone can help me it will be much appreciated.

Add this right after SetCamActive(cam, true);

RenderScriptCams(true, false, 1, true, true)

So it should be;

cam = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", pos.x, pos.y + 0.5, pos.z + 0.5, 0.0 ,0.0, heading, 60.00, false, 0)
SetCamActive(cam, true)
RenderScriptCams(true, false, 1, true, true)

When switching back to the player, when you call SetCamActive(cam, false), call that function after again, but with the first parameter as false;

SetCamActive(cam, false)
RenderScriptCams(false, false, 1, true, true)

Try that and if it works, mark this as the solution to help others that search for this sort of thing! :slightly_smiling_face:

it works but is there anyway to make the camera follow the player?

Not sure if there is a native for that (I honestly haven’t even checked), but it IS possible even without a native that locks the camera to the player.
Just loop and update the coordinates and rotation of the camera with the new player coordinates.

ok got it thanks