Jump to content

360* Camera


Recommended Posts

bool setCameraMatrix ( float positionX, float positionY, float positionZ [, float lookAtX, float lookAtY, float lookAtZ, float roll, float fov ] ) 

Required Arguments

positionX: The x coordinate of the camera's position.

positionY: The y coordinate of the camera's position.

positionZ: The z coordinate of the camera's position.

Optional Arguments

lookAtX: The x coordinate of the point the camera faces.

lookAtY: The y coordinate of the point the camera faces.

lookAtZ: The z coordinate of the point the camera faces.

roll: The camera roll angle, -180 to 180. A value of 0 means the camera sits straight, positive values will turn it counter-clockwise and negative values will turn it clockwise. -180 or 180 means the camera is upside down.

fov: the field of view angle, 0 to 180. The higher this value is, the more you will be able to see what is to your sides.

Link to comment
Guest Guest4401

Did you want something like this?

--clientside

local n = 0 
  
addEventHandler("onClientRender", getRootElement(), 
    function() 
        setCameraMatrix(1468.8785400391, -919.25317382813, 100.153465271, 1468.388671875, -918.42474365234, 99.881813049316, 0+n, 180) 
        n = n+0.2 
    end 
) 

Link to comment
local nCount = 0 
  
local nPlus = 0.1 
  
addEventHandler( 'onClientPreRender', root, 
    function( ) 
        if math.floor( nCount ) == 180 then 
            nCount = 0 
        end 
        nCount = nCount + nPlus 
        setCameraMatrix(  
            1468.8785400391, 
            -919.25317382813, 
            100.153465271, 
            1468.388671875, 
            -918.42474365234, 
            99.881813049316, 
            0, 
            nCount 
        ) 
    end 
) 

?

Link to comment
Guest Guest4401

Sorry for 2nd post, but I tested this time and it moves your camera 360 degrees.

local n = 0 
local speed = 3 
  
addEventHandler("onClientRender", getRootElement(), 
    function() 
        setCameraMatrix(1468.8785400391, -919.25317382813, 100.153465271, 0+n, 0, 0, 0, 180) 
        n = n+speed 
    end 
) 

I hope I helped you. :)

Link to comment
local nCount = 0 
  
local nPlus = 0.1 
  
addEventHandler( 'onClientPreRender', root, 
    function( ) 
        if math.floor( nCount ) == 180 then 
            nCount = 0 
        end 
        nCount = nCount + nPlus 
        setCameraMatrix(  
            1468.8785400391, 
            -919.25317382813, 
            100.153465271, 
            1468.388671875, 
            -918.42474365234, 
            99.881813049316, 
            0, 
            nCount 
        ) 
    end 
) 

?

This not working.

Did you want something like this?

--clientside

local n = 0 
  
addEventHandler("onClientRender", getRootElement(), 
    function() 
        setCameraMatrix(1468.8785400391, -919.25317382813, 100.153465271, 1468.388671875, -918.42474365234, 99.881813049316, 0+n, 180) 
        n = n+0.2 
    end 
) 

This have error:

Bad argument @ `setCamerMatrix`.

Link to comment
local nCount = 0 
  
local nPlus = 0.1 
  
addEventHandler( 'onClientPreRender', root, 
    function( ) 
        if math.floor( nCount ) == 180 then 
            nCount = 0 
        end 
        nCount = nCount + nPlus 
        setCameraMatrix(  
            1468.8785400391, 
            -919.25317382813, 
            100.153465271, 
            1468.388671875, 
            -918.42474365234, 
            99.881813049316, 
            0, 
            nCount 
        ) 
    end 
) 

?

This not working.

You kidding me?

Work perfectly.

Link to comment
local nCount = 0 
  
local nPlus = 0.1 
  
function setCameraOnPlayerJoin() 
    fadeCamera(source, true, 3) 
     setCameraMatrix( 
            1468.8785400391, 
            -919.25317382813, 
            100.153465271, 
            1468.388671875, 
            -918.42474365234, 
            99.881813049316, 
            0, 
            nCount 
        ) 
end 
addEventHandler("onPlayerJoin", getRootElement(), setCameraOnPlayerJoin) 
  
addEventHandler( 'onClientPreRender', root, 
    function( ) 
        if math.floor( nCount ) == 180 then 
            nCount = 0 
        end 
        nCount = nCount + nPlus 
        setCameraMatrix( 
            1468.8785400391, 
            -919.25317382813, 
            100.153465271, 
            1468.388671875, 
            -918.42474365234, 
            99.881813049316, 
            0, 
            nCount 
        ) 
    end 
) 

My script and not working.

Bad argument @ `setCamerMatrix`.

Edited by Guest
Link to comment
Guest Guest4401

You added this code to serverside or clientside? Why do I see onPlayerJoin (serverside event) and onClientPreRender(clientside event)?

Link to comment
Sorry for 2nd post, but I tested this time and it moves your camera 360 degrees.
local n = 0 
local speed = 3 
  
addEventHandler("onClientRender", getRootElement(), 
    function() 
        setCameraMatrix(1468.8785400391, -919.25317382813, 100.153465271, 0+n, 0, 0, 0, 180) 
        n = n+speed 
    end 
) 

I hope I helped you.

This working but it is fast and then gradually slows and stoped in 180 but i want full 360 rotate and repeat.

local nCount = 0 
  
local nPlus = 0.1 
  
addEventHandler( 'onClientPreRender', root, 
    function( ) 
        if math.floor( nCount ) == 180 then 
            nCount = 0 
        end 
        nCount = nCount + nPlus 
        setCameraMatrix(  
            1468.8785400391, 
            -919.25317382813, 
            100.153465271, 
            1468.388671875, 
            -918.42474365234, 
            99.881813049316, 
            0, 
            nCount 
        ) 
    end 
) 

?

This not working.

You kidding me?

Work perfectly.

It moves away not 360*

Link to comment
Guest Guest4401
Sorry for 2nd post, but I tested this time and it moves your camera 360 degrees.
local n = 0 
local speed = 3 
  
addEventHandler("onClientRender", getRootElement(), 
    function() 
        setCameraMatrix(1468.8785400391, -919.25317382813, 100.153465271, 0+n, 0, 0, 0, 180) 
        n = n+speed 
    end 
) 

I hope I helped you.

This working but it is fast and then gradually slows.

See my 2nd line :

local speed = 3 

Just make it 2 or 1 or 0.5 or whatever you want.

Link to comment
Sorry for 2nd post, but I tested this time and it moves your camera 360 degrees.
local n = 0 
local speed = 3 
  
addEventHandler("onClientRender", getRootElement(), 
    function() 
        setCameraMatrix(1468.8785400391, -919.25317382813, 100.153465271, 0+n, 0, 0, 0, 180) 
        n = n+speed 
    end 
) 

I hope I helped you.

This working but it is fast and then gradually slows.

See my 2nd line :

local speed = 3 

Just make it 2 or 1 or 0.5 or whatever you want.

and stoped in 180 but i want full 360 rotate and repeat.

Link to comment

People, there is more maths required to do the rotation. I don't know what it is like on that server because I haven't got time to check it but if you've used my modshop resource then you'd know how it works. Also, roll parameter in setCameraMatrix function is not the rotation like you all might thing.. It's the angle at which the camera is rotated (rolled) at. Imagine having a camera in your hand, point at something in front of you and move your wrist up and down, then just play what you've recorded. Can you see the difference?

And FOV (field of view or field of vision) parameter is how wide you can see. This is a camera lens variable. Read more about it here: http://en.wikipedia.org/wiki/Angle_of_view

I modified my old functions for easier use, just copy this entire code and call startRotatingCamera() and stopRotatingCamera() to do what the function names say:

function startRotatingCamera( ) 
    addEventHandler( "onClientPreRender", root, rotateCameraAroundPlayer ); 
end 
  
function stopRotatingCamera( ) 
    removeEventHandler( "onClientPreRender", root, rotateCameraAroundPlayer ); 
end 
  
local facing = 0 
local distance = 5; -- you can change this to change the distance between camera and the player 
local height = 1;  -- you can change this to change how much higher the camera should be above the player 
local speed = 0.0002 -- change this to speed up or slow down the camera rotation 
local gLocalPlayer = getLocalPlayer( ); 
function rotateCameraAroundPlayer( ) 
    local x, y, z = getElementPosition( gLocalPlayer ) 
    if isPedInVehicle( gLocalPlayer ) then 
        x, y, z = getElementPosition( getPedOccupiedVehicle( gLocalPlayer ) ) 
    end 
    local camX = x + math.cos( facing / math.pi * 180 ) * distance; 
    local camY = y + math.sin( facing / math.pi * 180 ) * distance; 
    setCameraMatrix( camX, camY, z + height, x, y, z ) 
    facing = facing + 0.0002 
end 

Link to comment

My code

local facing = 0 
local distance = 5; 
local height = 1; 
local speed = 0.0002 
local gLocalPlayer = getLocalPlayer(); 
  
function rotateCameraAroundPlayer() 
    local x, y, z = getElementPosition(gLocalPlayer) 
    if isPedInVehicle(gLocalPlayer) then 
        x, y, z = getElementPosition(getPedOccupiedVehicle(gLocalPlayer)) 
    end 
    local camX = x + math.cos(facing / math.pi * 180) * distance; 
    local camY = y + math.sin(facing / math.pi * 180) * distance; 
    setCameraMatrix(camX, camY, z + height, x, y, z) 
    facing = facing + 0.0002 
end 
  
function startRotatingCamera() 
    addEventHandler("onClientPreRender", root, rotateCameraAroundPlayer); 
end 
  
function stopRotatingCamera() 
    removeEventHandler("onClientPreRender", root, rotateCameraAroundPlayer); 
end 
  
function setCameraOnPlayerJoin() 
    fadeCamera(source, true, 3) 
    startRotatingCamera() 
end 
addEventHandler("onClientPlayerJoin", getRootElement(), setCameraOnPlayerJoin) 
  
function setPlayerColor() 
    setPlayerNametagColor(source, 0, 204, 0) 
end 
addEventHandler("onClientPlayerJoin", getRootElement(), setPlayerColor) 

Client side and not working !! :/

Edited by Guest
Link to comment

onClientPlayerJoin - "This event is triggered when a player joins a server. It is triggered for all players except the local player, as the local player joins the server before their client-side resources are started."

I don't know why people don't try to find the correct events... Always use onClientResourceStart if you want something happen for local player when he joins the server.

Link to comment
:/

Look at arguments function

fadeCamera 

I deleted fadeCamera and not working

Check the debugscript window.

If non of your resources use fadeCamera function then you will always have black screen because that's what happens when you join server that doesn't run any scripts.

Link to comment

try this:

local facing = 0 
local distance = 5; 
local height = 1; 
local speed = 0.0002 
  
function rotateCameraAroundPlayer() 
    local x, y, z = getElementPosition(localPlayer) 
    if isPedInVehicle(localPlayer) then 
        x, y, z = getElementPosition(getPedOccupiedVehicle(localPlayer)) 
    end 
    local camX = x + math.cos(facing / math.pi * 180) * distance; 
    local camY = y + math.sin(facing / math.pi * 180) * distance; 
    setCameraMatrix(camX, camY, z + height, x, y, z) 
    facing = facing + 0.0002 
end 
  
function startRotatingCamera() 
    addEventHandler("onClientPreRender", root, rotateCameraAroundPlayer) 
end 
  
function stopRotatingCamera() 
    removeEventHandler("onClientPreRender", root, rotateCameraAroundPlayer) 
end 
  
addEventHandler("onClientResourceStart", resourceRoot,function() --Use onClientResourceStart for localPlayer 
    fadeCamera(true, 3) --no need for source if the client is localPlayer 
    startRotatingCamera() 
    setPlayerNametagColor(0, 204, 0) --If it's client-side, don't add source 
end) 

I add comments to let you know the stuff your missing

Edited by Guest
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...