Holy hell that's overly complicated... I made this as a test one. Works fairly well IIRC.
-- Changes the camera position on pre-render (to avoid stuttering)
local function clientPreRender()
if not isPilotingCompatibleVehicle() then
return
end
local vehicle = getPedOccupiedVehicle(localPlayer)
local cameraX, cameraY, cameraZ = getPositionFromElementOffset(vehicle, 0, -7, 4)
local lookAtX, lookAtY, lookAtZ = getPositionFromElementOffset(vehicle, 0, 0, 2)
local _, rotY= getElementRotation(vehicle)
setCameraMatrix(cameraX, cameraY, cameraZ, lookAtX, lookAtY, lookAtZ, (rotY*-1))
end
addEventHandler("onClientPreRender", root, clientPreRender)