Topic: 1st Person Camera Made Easier

I wanted to adjust the Sponza 1st person script so that it can be used in other projects easier. Here is the code:

-----------------------------------------------------------------------------------
-- Maratis
-- Jules script test
-----------------------------------------------------------------------------------

Head = getObject("Head")

function Initialize()
    dx = 0.0
    dy = 0.0

    centerCursor()
    mx = getAxis("MOUSE_X")
    my = getAxis("MOUSE_Y")
end

Initialize()

function LookWith(object)

    -- rotate object (X mouse)
    rotate(object, {0, 0, -1}, dx*100)
    
    -- rotate object (Y mouse)
    rotate(object, {-1, 0, 0}, dy*100, "local")    
    rotation = getRotation(object)
        
    if rotation[1] > 90 then
        rotation[1] = 90
    elseif rotation[1] < -90 then
        rotation[1] = -90
    end

    setRotation(object, rotation)
    
    -- get mouse direction
    dx = getAxis("MOUSE_X") - mx
    dy = getAxis("MOUSE_Y") - my

    -- center cursor
    centerCursor()
    
    mx = getAxis("MOUSE_X")
    my = getAxis("MOUSE_Y")
end

-- scene update
function onSceneUpdate()
        LookWith(Head)
end

Last edited by Tutorial Doctor (2014-08-21 19:43:42)

Re: 1st Person Camera Made Easier

I put the functions in separate file and linked it using the "dofile()" function

Last edited by Tutorial Doctor (2014-08-21 19:51:36)