Okay, i write this code and it sets camera always behind car when i press A/D keys(when i turn).
local camState = false
local cameraHookEnabled = false
local origFieldOfView = 0
local cameraResetTimer
function vehicleCameraHookUpdate()
if not isPedInVehicle(localPlayer) then return end
local vehicle = getPedOccupiedVehicle (localPlayer)
if getVehicleController(vehicle) ~= localPlayer then return end
local vehLeftState = getPedAnalogControlState( localPlayer, "vehicle_left" )
local vehRightState = getPedAnalogControlState( localPlayer, "vehicle_right" )
if (vehLeftState > 0.3 or vehRightState > 0.3) then
camState = true
else camState = false end
if camState then
-- I found this code somewhere in forum, it does something like i need but not smooth at all and camera always goes up after turning a while.
-- I have no idea what this code actually do.
local Sx,Sy,Sz = getElementPosition (vehicle)
local _,_,pR = getElementRotation (localPlayer)
pR = ((pR+90) * 3.141592653 * 2)/360; --edit "90" to change the rotation.
local lookAtX, lookAtY, lookAtZ = Sx + math.cos(pR), Sy + math.sin(pR), Sz
setCameraTarget( lookAtX, lookAtY, lookAtZ )
-- This makes camera always behind car and best solution i found wich at least works, but is it good solution at all on every render update?
-- setCameraTarget(localPlayer)
-- setCameraMatrix(0, 0, 0)
-- setCameraTarget(localPlayer)
end
end
addEventHandler("onClientPreRender", root, vehicleCameraHookUpdate)
Now my question is how to get correct X,Y,Z for setCameraTarget so when i turn maximum look offset should be like i posted in screenshot 1 in topic and not only behind car like my code do.