Код покажите.
Ранее я делал подобное с setCameraMatrix, но так как с математикой у меня не очень, были мелкие баги. Но как появилась getCamera() на стороне клиента - я быстренько всё это переписал.
Собственно тут всё просто, получаете элемент камеры, атачите её к чему нужно и всё. Если нужно реализовать вращение - то есть setElementAttachedOffsets.
Сначала попробовал примерно так (код не помню написал по-быстрому, поэтому не тестился)
local player = getLocalPlayer()
local r_root = getRootElement()
local camera
addEventHandler( 'onClientVehicleEnter', r_root,
function ( thePlayer, theSeat )
if thePlayer == player and theSeat == 0 then
if isElement( camera ) then
destroyElement( camera )
end
local x, y, z = getPedBonePosition( thePlayer, 8 )
camera = createObject( 3803, x, y, z )
setElementAlpha( camera, 0 )
attachElements( thePlayer, camera )
setCameraTarget( camera )
end
end)
addEventHandler( 'onClientVehicleStartExit', r_root,
function ( thePlayer )
if thePlayer == player then
if isElement( camera ) then
destroyElement( camera )
end
setCameraTarget( thePlayer )
end
end)
И в нем была проблема в том, что attachElements и setCameraTarget возвращали false. Потом попробовал как в ресурсе cockpit, но камера стала показывать внутренности машины (я так и не понял куда направлялась камера). Потом решил через getCamera()
local player = getLocalPlayer()
local r_root = getRootElement()
local camera = getCamera()
addEventHandler( 'onClientVehicleEnter', r_root,
function ( thePlayer, theSeat )
if thePlayer == player and theSeat == 0 then
local x, y, z = getPedBonePosition( thePlayer, 8 )
setCameraTarget( x, y, z )
setCameraClip( true, false )
end
end)
addEventHandler( 'onClientVehicleStartExit', r_root,
function ( thePlayer )
if thePlayer == player then
setCameraTarget( thePlayer )
setCameraClip( true, true )
end
end)
Получилось как-будто я и не писал код вообще. Хотелось все таки как-то покрасивей и попроще, в итоге ничего не получилось.