No need to get your knickers in a twist, that’ll just discourage people from replying altogether.
A few things:
- Firstly you set
pos
to 2 units above the ped’s head once at the start of the script, but then never update that value, which results in nothing moving, I can’t tell if that’s what you intended to do or not, but I removed it since it didn’t make much sense to me.
- Secondly, you said you want the script camera to follow the rotation of the prop camera, but the prop camera does not move, so I was a bit lost on how you were saying solutions were not working. For the purposes of the code below, I made it so the camera prop followed the ped rotation, and then the script camera follows the prop camera rotation. If you have a different source rotation for the camera prop you can remove that line, I labeled it for you.
The code below does the following:
- Create a camera prop above the ped
- Updates the camera prop’s position and rotation to match that of the ped (+2 units above)
- Creates a script camera
- Attaches the script camera to the camera prop
- Updates the script camera’s rotation to match that of the ped
local cam, obj
Citizen.CreateThread(function()
local hash = GetHashKey("prop_pap_camera_01")
RequestModel(hash)
while not HasModelLoaded(hash) do
Citizen.Wait(100)
end
-- Spawn below the player then set in place
obj = CreateObject(hash, GetEntityCoords(PlayerPedId()) - vector3(0, 0, -50), true, true, true)
Citizen.CreateThread(function()
while true do
local ped = PlayerPedId()
-- You could also attach the prop to the ped, if that is your end goal
SetEntityCoords(obj, GetEntityCoords(ped) + vector3(0,0,2))
-- You can remove this if you do not want the prop to follow the player rotation
SetEntityRotation(obj, GetEntityRotation(ped, 2) + vector3(0, 0, 180), 2, true)
-- Uncomment this if you want the camera to move with the mouse
--SetEntityRotation(obj, GetGameplayCamRot(2), 2, true)
Citizen.Wait(1)
end
end)
cam = CreateCam("DEFAULT_SCRIPTED_CAMERA", 1)
AttachCamToEntity(cam, obj, vector3(0,0,0), true)
Citizen.CreateThread(function()
while true do
local obj_rot = GetEntityRotation(obj, 2)
-- This points the camera upwards, unclear if this is intended or not
obj_rot = obj_rot + vector3(20.0, 0.0, 180)
SetCamRot(cam, obj_rot, 2)
Citizen.Wait(1)
end
end)
RenderScriptCams(1, 0, 0, 1, 1)
end)
-- Delete everything when script stops
AddEventHandler("onResourceStop", function(resource)
if (GetCurrentResourceName() ~= resource) then
return
end
DeleteObject(obj)
DestroyCam(cam, 0)
RenderScriptCams(0, 0, 1, 1, 1)
end)
Removed a few things:
local pos
, for the reasons I explained above.
SetCamCoord(cam, spawn)
, spawn
was not defined, and if you attach the camera to the prop then you don’t need to update the position, only the rotation.
SetEntityAngularVelocity
, no idea what you were doing with this.
Hopefully that’s what you’re after, or at least points you in the direction of what you’re after, because even after “reading carefully” and looking at the code you posted, I’m still not clear on what you’re trying to do.