Jump to content

move camera by mouse like normal


Recommended Posts

This is just a fragment

I want to move camera like normal around player by mouse

function mouse3(cursorX,cursorY) 
    setElementData(localPlayer,"moveX",cursorX) 
    setElementData(localPlayer,"moveY",cursorY) 
    if cursorX > cX then -- move right 
    setCameraMatrix ( x, y1, z2, x, y, z + 1 ) 
    elseif cursorX < cX then -- move left 
    setCameraMatrix ( x, y, z2, x, y, z - 1 ) 
    elseif cursorY > cY then -- move bottom 
    --setCameraMatrix ( x, y, z2, x, y, z - 1 ) 
    elseif cursorY < cY then -- move up 
    --setCameraMatrix ( x, y, z2, x, y, z - 1 ) 
    end 
end 
addEventHandler("onClientCursorMove",root,mouse3) 
  

Link to comment

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) 

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...