Jump to content

Side Camera


Enigma666

Recommended Posts

  
function getPositionFromElementOffset(element,offX,offY,offZ) 
    local m = getElementMatrix (element) 
    local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1]   
    local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] 
    local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] 
    return x, y, z                    
end 
  
addEventHandler("onClientRender", getRootElement(),  
    function()  
        local x,y,z = getPositionFromElementOffset(localPlayer, 0.5, -3, 0.5) 
        setCameraMatrix(x, y, z, x, y, z) 
    end 
) 
  

I have this. works fine as i said, but if i press D for example when im standing, the camera doesnt follow the players rotation to the angle, and idk which part of the matrix is supposed to do that.

Link to comment

Ah you mean when the ped rotates to make the camera follow him?

Try this, i'm not sure thought.

  
  
function getPositionFromElementOffset(element,offX,offY,offZ) 
    local m = getElementMatrix (element) 
    local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1]   
    local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] 
    local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] 
    return x, y, z                   
end 
  
addEventHandler("onClientRender", getRootElement(), 
    function() 
        local _,_,rot = getElementRotation(localPlayer) 
local max = 3 
local angle = math.rad(rot+90) -- +90 to actually make it from the "back" of the ped. 
local plusX,plusY = math.cos(angle)*max,math.sin(angle)*max 
        local x,y,z = getPositionFromElementOffset(localPlayer, 0.5 + plusX, -3 + plusY, 0.5) 
        setCameraMatrix(x, y, z, x, y, z) 
    end 
) 
  

Link to comment
Doesnt work sadly.

Try this. it should have an effect upon moving the ped...

  
  
function getPositionFromElementOffset(element,offX,offY,offZ) 
    local m = getElementMatrix (element) 
    local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1]   
    local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] 
    local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] 
    return x, y, z                   
end 
  
addEventHandler("onClientRender", getRootElement(), 
    function() 
        local _,_,rot = getElementRotation(localPlayer) 
local max = 3 
local angle = math.rad(rot+90) -- +90 to actually make it from the "back" of the ped. 
local plusX,plusY = math.cos(angle)*max,math.sin(angle)*max 
        local x,y,z = getPositionFromElementOffset(localPlayer,plusX,plusY, 0.5) 
        setCameraMatrix(x, y, z, x, y, z) 
    end 
) 
  

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...