Jump to content

setCameraMatrix


Blaawee

Recommended Posts

is there any function to make the camera faceing the ped, i'm trying do it with :

setCameraMatrix 

this what i'm tryin do :

function setCamFacenPed ( thePed, x, y, z, lookAtX, lookAtY, lookAtZ ) 
    x, y, z = getElementPosition( thePed ) 
    lookAtX, lookAtY, lookAtZ = getElementRotation ( thePed ) 
    return setCameraMatrix ( thePed, x, y, z, lookAtX, lookAtY, lookAtZ ) 
end 
  
male = createPed ( 0, 9.2, 11.95, 4.5171875,340 ) 
setCamFacenPed( male ) 

Link to comment
is there any function to make the camera faceing the ped, i'm trying do it with :
setCameraMatrix 

this what i'm tryin do :

function setCamFacenPed ( thePed, x, y, z, lookAtX, lookAtY, lookAtZ ) 
    x, y, z = getElementPosition( thePed ) 
    lookAtX, lookAtY, lookAtZ = getElementRotation ( thePed ) 
    return setCameraMatrix ( thePed, x, y, z, lookAtX, lookAtY, lookAtZ ) 
end 
  
male = createPed ( 0, 9.2, 11.95, 4.5171875,340 ) 
setCamFacenPed( male ) 

Try with this

Client

  
  
local Face = 0  
  
function setCamFacenPed() 
    local x,y,z = getElementPosition(male) 
    local x,y,z = getElementPosition(localPlayer) 
        local MatriX = x + math.cos( Face / math.pi * 180 ) * 5 
        local MatriY = y + math.sin( Face / math.pi * 180 ) * 5 
        setCameraMatrix( MatriX, MatriY, z+1, x, y, z ) 
        Face = Face + 0.0002 
end 
  
male = createPed ( 0, 9.2, 11.95, 4.5171875,340 ) 
  

if you need setCameraMatrix

addEventHandler( "onClientRender", root, setCamFacenPed) 
  

if you need remove camera

  
removeEventHandler( "onClientRender", root, setCamFacenPed) 
setCameraTarget ( localPlayer ) 
  

Link to comment
is there any function to make the camera faceing the ped, i'm trying do it with :
setCameraMatrix 

this what i'm tryin do :

function setCamFacenPed ( thePed, x, y, z, lookAtX, lookAtY, lookAtZ ) 
    x, y, z = getElementPosition( thePed ) 
    lookAtX, lookAtY, lookAtZ = getElementRotation ( thePed ) 
    return setCameraMatrix ( thePed, x, y, z, lookAtX, lookAtY, lookAtZ ) 
end 
  
male = createPed ( 0, 9.2, 11.95, 4.5171875,340 ) 
setCamFacenPed( male ) 

setCameraMatrix work only with players, not peds. And client side not required player.

i guess this is what you need https://wiki.multitheftauto.com/wiki/FindRotation

Link to comment
We cannot help you if you don't know what you want.
is there any function to make the camera faceing the ped, i'm trying do it with :
setCameraMatrix 

this what i'm tryin do :

function setCamFacenPed ( thePed, x, y, z, lookAtX, lookAtY, lookAtZ ) 
    x, y, z = getElementPosition( thePed ) 
    lookAtX, lookAtY, lookAtZ = getElementRotation ( thePed ) 
    return setCameraMatrix ( thePed, x, y, z, lookAtX, lookAtY, lookAtZ ) 
end 
  
male = createPed ( 0, 9.2, 11.95, 4.5171875,340 ) 
setCamFacenPed( male ) 

Link to comment

yup :)

Edit :

function setCamFacenPed ( thePed, x, y, z, lookAtX, lookAtY, lookAtZ ) 
    local peds = getElementsByType ( "ped" ) 
    if peds then  
        for k,thePed in ipairs(peds) do 
            x, y, z = getElementPosition( thePed ) 
            lookAtX, lookAtY = GetPedCameraRotation( thePed ) 
            lookAtZ = setPedCameraRotation ( thePed, 180 ) 
        end  
        return setCameraMatrix ( thePed, x, y, z, lookAtX, lookAtY, lookAtZ ) 
    end 
end 
  
male = createPed ( 0, 9.2, 11.95, 4.5171875,340 ) 
setCamFacenPed( male ) 

Link to comment
yup :)

Edit :

function setCamFacenPed ( thePed, x, y, z, lookAtX, lookAtY, lookAtZ ) 
    local peds = getElementsByType ( "ped" ) 
    if peds then  
        for k,thePed in ipairs(peds) do 
            x, y, z = getElementPosition( thePed ) 
            lookAtX, lookAtY = GetPedCameraRotation( thePed ) 
            lookAtZ = setPedCameraRotation ( thePed, 180 ) 
        end  
        return setCameraMatrix ( thePed, x, y, z, lookAtX, lookAtY, lookAtZ ) 
    end 
end 
  
male = createPed ( 0, 9.2, 11.95, 4.5171875,340 ) 
setCamFacenPed( male ) 

Well , this code made no sense too.

Link to comment
function setCamFacenPed ( thePed ) 
    if isElement(thePed) then 
        x, y, z = getElementPosition( thePed ) 
        cx, cy, cz = findRotation( getElementPosition( thePed ) ) 
        setCameraMatrix( cx, cy, cz, x, y, z ) 
    end 
    addEventHandler("onClientPreRender", root, setCamFacenPed ) 
end 
  
function findRotation( x1, y1, x2, y2 ) 
    local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) ) 
    if t < 0 then  
        t = t + 360  
    end 
    return t 
end 
  
male = createPed ( 0, 9.2, 11.95, 4.5171875,340 ) 
setCamFacenPed( male ) 

Link to comment

Is the ped in the movement? If it is then you will have to use an event onClientPreRender.

function getPointFromDistanceRotation(x, y, dist, angle) 
    angle = math.rad(90 - angle); 
    local dx = math.cos(angle) * dist; 
    local dy = math.sin(angle) * dist; 
    return x+dx, y+dy; 
end 
  
-- dist = distance 
function getPointInFrontOfPed( ped, dist ) 
    local rz = getElementRotation( ped, "ZXY" ); 
    local x,y = getElementPosition( ped ); 
    return getPointFromDistanceRotation( x, y, dist, rz ); 
end 
  
-- every time you want to set camera in front of ped use this function: 
function setCameraFacingPed( ped, dist ) 
    local x,y,z = getElementPosition( ped ); 
    local fx, fy = getPointInFrontOfPed( ped, dist ); 
    setCameraMatrix( fx, fy, z, x, y, z ); 
end 
  
-- if you want the camera to follow the ped but still face the ped: 
addEventHandler( "onClientPreRender", root, 
    function( ) 
        setCameraFacingPed( ped, 3 ); -- remember "ped" needs to be ped/player element 
    end 
) 
  

I haven't tested it but when I rubber duck debug it, the code should work just as you want.

Link to comment
Is the ped in the movement? If it is then you will have to use an event onClientPreRender.
function getPointFromDistanceRotation(x, y, dist, angle) 
    angle = math.rad(90 - angle); 
    local dx = math.cos(angle) * dist; 
    local dy = math.sin(angle) * dist; 
    return x+dx, y+dy; 
end 
  
-- dist = distance 
function getPointInFrontOfPed( ped, dist ) 
    local rz = getElementRotation( ped, "ZXY" ); 
    local x,y = getElementPosition( ped ); 
    return getPointFromDistanceRotation( x, y, dist, rz ); 
end 
  
-- every time you want to set camera in front of ped use this function: 
function setCameraFacingPed( ped, dist ) 
    local x,y,z = getElementPosition( ped ); 
    local fx, fy = getPointInFrontOfPed( ped, dist ); 
    setCameraMatrix( fx, fy, z, x, y, z ); 
end 
  
-- if you want the camera to follow the ped but still face the ped: 
addEventHandler( "onClientPreRender", root, 
    function( ) 
        setCameraFacingPed( ped, 3 ); -- remember "ped" needs to be ped/player element 
    end 
) 
  

I haven't tested it but when I rubber duck debug it, the code should work just as you want.

and this what i want to do :D

thx 50p

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