Imposter Posted February 18, 2013 Share Posted February 18, 2013 Hey guys, I am trying to make a camera that looks up at the back up the car near the left wheel. Can somebody please help me out? function setCamera() local x, y, z = getElementPosition(getLocalPlayer()) local rx, ry, rz = getElementRotation(getLocalPlayer()) setCameraMatrix(x-3, y-3, z, x+1, y+1, z+1) end addEventHandler("onClientPreRender", root, setCamera) addEventHandler("onClientResourceStart", resourceRoot, setCamera) addCommandHandler("setcamera", setCamera) --[[function resetCamera() end addCommandHandler("resetcamera", resetCamera)--]] Link to comment
Imposter Posted February 18, 2013 Author Share Posted February 18, 2013 --Bump-- Anyone? TAPL? Solidsnake14? 50p? Link to comment
manve1 Posted February 18, 2013 Share Posted February 18, 2013 ur trying to make it near a vehicles wheel but ur getting position of a player? why not the position of the vehicle a player is in who triggered the command? Link to comment
Imposter Posted February 18, 2013 Author Share Posted February 18, 2013 ur trying to make it near a vehicles wheel but ur getting position of a player? why not the position of the vehicle a player is in who triggered the command? But that still doesn't explain how to set the rotation so that it is always in that view function setCamera() local theCar = getPedOccupiedVehicle(getLocalPlayer()) local x, y, z = getElementPosition(theCar) local rx, ry, rz = getElementRotation(theCar) setCameraMatrix(x-3*rx, y-3*ry, z, x+1, y+1, z+1) end addEventHandler("onClientPreRender", root, setCamera) addEventHandler("onClientResourceStart", resourceRoot, setCamera) addCommandHandler("setcamera", setCamera) Link to comment
50p Posted February 18, 2013 Share Posted February 18, 2013 https://wiki.multitheftauto.com/wiki/GetElementMatrix function getPositionFromElementOffset(element,offX,offY,offZ) local m = getElementMatrix ( element ) -- Get the matrix local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1] -- Apply transform 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 -- Return the transformed point end function setCamera() local theCar = getPedOccupiedVehicle(localPlayer) if theCar then local cx, cy, cz = getPositionFromElementOffset( theCar, 2, -2, 0 ); -- camera position at the left read side of the car (2 units to the left and 2 units to the back) local lx, ly, lz = getPositionFromElementOffset( theCar, 2, 2, 0 ); -- get the position where the camera will look (2 units to the left and 2 units to the front) setCameraMatrix( cx, cy, cz, lx, ly, lz ); end end addEventHandler("onClientPreRender", root, setCamera) addEventHandler("onClientResourceStart", resourceRoot, setCamera) addCommandHandler("setcamera", setCamera) Link to comment
Imposter Posted February 18, 2013 Author Share Posted February 18, 2013 https://wiki.multitheftauto.com/wiki/GetElementMatrix function getPositionFromElementOffset(element,offX,offY,offZ) local m = getElementMatrix ( element ) -- Get the matrix local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1] -- Apply transform 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 -- Return the transformed point end function setCamera() local theCar = getPedOccupiedVehicle(localPlayer) if theCar then local cx, cy, cz = getPositionFromElementOffset( theCar, 2, -2, 0 ); -- camera position at the left read side of the car (2 units to the left and 2 units to the back) local lx, ly, lz = getPositionFromElementOffset( theCar, 2, 2, 0 ); -- get the position where the camera will look (2 units to the left and 2 units to the front) setCameraMatrix( cx, cy, cz, lx, ly, lz ); end end addEventHandler("onClientPreRender", root, setCamera) addEventHandler("onClientResourceStart", resourceRoot, setCamera) addCommandHandler("setcamera", setCamera) thank you, i didnt know how to do it, now i do, thanks so much 50p. Link to comment
50p Posted February 18, 2013 Share Posted February 18, 2013 No problem. Play around with different values to suit your needs. I just used 2 as an example. Link to comment
Imposter Posted February 18, 2013 Author Share Posted February 18, 2013 No problem. Play around with different values to suit your needs. I just used 2 as an example. Mhm, I used local cx, cy, cz = getPositionFromElementOffset( theCar, 2, -4, 0 ); local lx, ly, lz = getPositionFromElementOffset( theCar, 1, 3, 1 ); Link to comment
Imposter Posted February 18, 2013 Author Share Posted February 18, 2013 One more quick question, why does math.random not work with floats? NVM, i just divided it. 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