here's simple camera moving:
local camera = {}
local currentCameraView = 2
local cameraView = {}
cameraView[1] = 5
cameraView[2] = 10
cameraView[3] = 15
cameraView[4] = 20
camera.dist = cameraView[currentCameraView]
camera.speed = 10
camera.x = math.rad(60)
camera.y = math.rad(60)
camera.z = math.rad(15)
camera.maxZ = math.rad(89)
camera.minZ = math.rad(-45)
addEventHandler("onClientPreRender", getRootElement(),
function()
local x, y, z = getElementPosition(localPlayer)
z = z + 0.2
local camDist = camera.dist
local cosZ = math.cos(camera.z)
local camX = x + math.cos(camera.x)*camDist*cosZ
local camY = y + math.sin(camera.y)*camDist*cosZ
local camZ = z + math.sin(camera.z)*camDist
--[[
local hit, hitX, hitY, hitZ = processLineOfSight(x, y, z, camX, camY, camZ, true, false, false, true, false, false, false, false)
if(hit)then
camDist = getDistanceBetweenPoints3D(x, y, z, hitX, hitY, hitZ)
camDist = camDist - 2
if(camDist > camera.maxDist)then
camDist = camera.maxDist
end
if(camDist < camera.minDist)then
camDist = camera.minDist
end
end
camX = x + math.cos(camera.x)*camDist*cosZ
camY = y + math.sin(camera.y)*camDist*cosZ
camZ = z + math.sin(camera.z)*camDist
--]]
setCameraMatrix(camX, camY, camZ, x, y, z)
end)
addEventHandler("onClientCursorMove", getRootElement(),
function(curX, curY, absX, absY)
local diffX = curX - 0.5
local diffY = curY - 0.5
local camX = camera.x - diffX*camera.speed
local camY = camera.y - diffX*camera.speed
local camZ = camera.z + (diffY*camera.speed)/math.pi
if(camZ > camera.maxZ)then
camZ = camera.maxZ
end
if(camZ < camera.minZ)then
camZ = camera.minZ
end
camera.x = camX
camera.y = camY
camera.z = camZ
end)
bindKey("change_camera", "down",
function()
currentCameraView = currentCameraView - 1
if(currentCameraView < 1)then
currentCameraView = #cameraView
end
camera.dist = cameraView[currentCameraView]
end)