Dzsozi (h03) Posted April 5, 2014 Share Posted April 5, 2014 Hello everyone! Today I played a little with camera functions and I found smoothMoveCamera in useful functions section. My question is that how can I attach this moving camera to the player? Here's the code: local sm = {} sm.moov = 0 sm.object1, sm.object2 = nil, nil local function removeCamHandler () if(sm.moov == 1) then sm.moov = 0 removeEventHandler ( "onClientPreRender", getRootElement(), camRender ) end end local function camRender () local x1, y1, z1 = getElementPosition ( sm.object1 ) local x2, y2, z2 = getElementPosition ( sm.object2 ) setCameraMatrix ( x1, y1, z1, x2, y2, z2 ) end function smoothMoveCamera ( x1, y1, z1, x1t, y1t, z1t, x2, y2, z2, x2t, y2t, z2t, time ) if(sm.moov == 1) then return false end sm.object1 = createObject ( 1337, x1, y1, z1 ) sm.object2 = createObject ( 1337, x1t, y1t, z1t ) setElementAlpha ( sm.object1, 0 ) setElementAlpha ( sm.object2, 0 ) setObjectScale(sm.object1, 0.01) setObjectScale(sm.object2, 0.01) moveObject ( sm.object1, time, x2, y2, z2, 0, 0, 0, "InOutQuad" ) moveObject ( sm.object2, time, x2t, y2t, z2t, 0, 0, 0, "InOutQuad" ) addEventHandler ( "onClientPreRender", getRootElement(), camRender ) sm.moov = 1 setTimer ( removeCamHandler, time, 1 ) setTimer ( destroyElement, time, 1, sm.object1 ) setTimer ( destroyElement, time, 1, sm.object2 ) return true end bindKey("k", "down", function() local px, py, pz = getElementPosition(localPlayer) local x, y, z, lx, ly, lz = getCameraMatrix (localPlayer) local x2, y2, z2, lx2, ly2, lz2 = getCameraMatrix (localPlayer) smoothMoveCamera(x, y, z, lx, ly, lz, x2, y2, z2 + 50, lx2, ly2, lz2 - 50, 12000) end ) I binded K button to test it, it's working, but I want to attach the smoothMoveCamera to the player. How is this even possible? Link to comment
Alexs Posted April 5, 2014 Share Posted April 5, 2014 You can use 'attachElements' and attach 'sm.object2' to the 'localPlayer'. Link to comment
Dzsozi (h03) Posted April 5, 2014 Author Share Posted April 5, 2014 You can use 'attachElements' and attach 'sm.object2' to the 'localPlayer'. Okay, I will try it, thank you for your answer! Link to comment
Castillo Posted April 5, 2014 Share Posted April 5, 2014 I don't know if it could be useful for what you're trying to do, but maybe you can make use of the recently added getCamera function. https://wiki.multitheftauto.com/wiki/GetCamera Link to comment
Dzsozi (h03) Posted April 6, 2014 Author Share Posted April 6, 2014 I don't know if it could be useful for what you're trying to do, but maybe you can make use of the recently added getCamera function.https://wiki.multitheftauto.com/wiki/GetCamera I have already tried it, but it's not working. 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