Enigma666 Posted January 19, 2015 Share Posted January 19, 2015 Hi. Is something like this possible in MTA? Im talking about the camera being a little offset and not centered [not when shooting, by default], if so, is it also possible to make it work with the default camera rotation? Thanks. Link to comment
.:HyPeX:. Posted January 19, 2015 Share Posted January 19, 2015 Yeah, pretty much. https://wiki.multitheftauto.com/wiki/GetElementMatrix Read the examples mostly. Then for rotation, https://wiki.multitheftauto.com/wiki/OnClientCursorMove. Link to comment
Enigma666 Posted January 19, 2015 Author Share Posted January 19, 2015 got the position part, gotta have a few problems with rotation tho. Link to comment
.:HyPeX:. Posted January 19, 2015 Share Posted January 19, 2015 got the position part, gotta have a few problems with rotation tho. Why so? its just moving off with the event.. Link to comment
Enigma666 Posted January 19, 2015 Author Share Posted January 19, 2015 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
.:HyPeX:. Posted January 20, 2015 Share Posted January 20, 2015 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
Enigma666 Posted January 20, 2015 Author Share Posted January 20, 2015 Doesnt work sadly. Link to comment
.:HyPeX:. Posted January 20, 2015 Share Posted January 20, 2015 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
Enigma666 Posted January 20, 2015 Author Share Posted January 20, 2015 i think the camera rotates, but keeps looking at the position it was looking at before the rotation. Link to comment
.:HyPeX:. Posted January 20, 2015 Share Posted January 20, 2015 i think the camera rotates, but keeps looking at the position it was looking at before the rotation. Aaaah i see. It was your bad. You didnt defined Look at XYZ. Check for some matrices on how to find the front of the ped to aim and then add an extra rotation according to aim Link to comment
Moderators IIYAMA Posted January 20, 2015 Moderators Share Posted January 20, 2015 Afaik you can also re-attach your camera to your ped. Take a look at the example at this page: https://wiki.multitheftauto.com/wiki/GetCamera Link to comment
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