Blaawee Posted November 8, 2012 Posted November 8, 2012 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 )
MR.S3D Posted November 8, 2012 Posted November 8, 2012 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 )
TAPL Posted November 8, 2012 Posted November 8, 2012 You need onClientPreRender for setCameraMatrix, or it will be lagged.
Blaawee Posted November 8, 2012 Author Posted November 8, 2012 will, this is not what i want .. i'm making function cuse i have a lot of peds ! waiting for expert ..
TAPL Posted November 8, 2012 Posted November 8, 2012 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
Blaawee Posted November 8, 2012 Author Posted November 8, 2012 so what's do i have to do then if i can't set "setCameraMatrix" with the peds !
Tete omar Posted November 8, 2012 Posted November 8, 2012 so what's do i have to do then if i can't set "setCameraMatrix" with the peds ! What do you want with 'setCameraMatrex' , it moves the game's cam to some position you define ..
TAPL Posted November 8, 2012 Posted November 8, 2012 so what's do i have to do then if i can't set "setCameraMatrix" with the peds ! That because you don't need "setCameraMatrix", you need setPedRotation. This function will help you https://wiki.multitheftauto.com/wiki/FindRotation
Blaawee Posted November 8, 2012 Author Posted November 8, 2012 (edited) still not get it .. What about 'getCameraMatrix' ? Edited November 8, 2012 by Guest
Tete omar Posted November 8, 2012 Posted November 8, 2012 We cannot help you if you don't know what you want.
Blaawee Posted November 8, 2012 Author Posted November 8, 2012 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 )
Blaawee Posted November 8, 2012 Author Posted November 8, 2012 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 )
Tete omar Posted November 8, 2012 Posted November 8, 2012 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.
TAPL Posted November 8, 2012 Posted November 8, 2012 well, any help ? I will post the link for the third time https://wiki.multitheftauto.com/wiki/FindRotation I hope i won't need to post it again.
Blaawee Posted November 8, 2012 Author Posted November 8, 2012 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 )
Castillo Posted November 8, 2012 Posted November 8, 2012 That's wrong, findRotation returns only ONE argument, the rotation, and you must fill FOUR arguments, not THREE.
Renkon Posted November 8, 2012 Posted November 8, 2012 setCameraTarget Once targeting.. use setCameraMatrix
Blaawee Posted November 8, 2012 Author Posted November 8, 2012 offf, :@ i think i have to forget about it, thx.
50p Posted November 8, 2012 Posted November 8, 2012 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.
Blaawee Posted November 9, 2012 Author Posted November 9, 2012 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 thx 50p
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now