diegofkda Posted February 6, 2012 Share Posted February 6, 2012 Well, we all know that making a camera movement onClientRender causes desync (the camera lags). Well, that's what's happening but onClientPreRender (with a minor intensity) so I wanted to know what's the problem (I know this isn't the best way to make what I'm making, but I'm tired with these math calculations). object1 = createObject ( 1097, 0, 0, 0 ) setElementAlpha ( object1, 0 ) vehicle1 = createVehicle ( 441, 0, 0, 0 ) setElementAlpha ( vehicle1, 0 ) attachElements ( vehicle1, object1, 5, 0, 0.8 ) speed = 8 wheelRotation = 0 wheelRotationY = 0 addEventHandler ( "onClientCursorMove", root, function (cursorX, cursorY, absoluteX, absoluteY) if isCursorShowing ( ) then return end abx = (absoluteX*1024)/sWidth if abx < 512 then speed2 = (512-abx)/speed wheelRotation = wheelRotation-speed2 elseif abx > 512 then speed2 = (abx-512)/speed wheelRotation = wheelRotation+speed2 end aby = (absoluteY*768)/sHeight if aby > 384 then speed2 = (384-aby)/speed wheelRotationY = wheelRotationY-speed2 elseif aby < 384 then speed2 = (aby-384)/speed wheelRotationY = wheelRotationY+speed2 end setElementRotation ( object1, 0, wheelRotationY, wheelRotation ) end) function onClientPreRender() local vehicle = getPedOccupiedVehicle ( getLocalPlayer() ) isCamera = true x, y, z = getElementPosition ( localPlayer ) setElementPosition ( object1, x, y, z+0.5 ) x1, y1, z1 = getElementPosition ( object1 ) x2, y2, z2 = getElementPosition ( vehicle1 ) setCameraMatrix ( x2, y2, z2, x1, y1, z1, 0, 80 ) end addEventHandler ( "onClientPreRender", root, onClientPreRender ) Test it, works quite fine, but it's like it desyncs. Link to comment
karlis Posted February 6, 2012 Share Posted February 6, 2012 id say that you should use freecam resource as a base, and tear parts down/add new as you go. and no, you are not going to make it without sin and cos. Link to comment
diegofkda Posted February 6, 2012 Author Share Posted February 6, 2012 This one works quite fine dude... but it's not what I want to do vehicle = getPedOccupiedVehicle ( getLocalPlayer() ) centre = createObject ( 1097, 0, 0, 0 ) setElementAlpha ( centre, 0 ) point = createObject ( 1097, 0, 0, 0 ) setElementAlpha ( point, 0 ) speed = 0.8/15 cx = 0 cy = -5 cz = 1 ox = 0 oy = 0 oz = 1 isAKeyPressed = false isDKeyPressed = false areAllStock = true function getA() aTimer = setTimer ( function () isAKeyPressed = true isATimerRunning = false end, 150, 1 ) isATimerRunning = true end function getD() dTimer = setTimer ( function () isDKeyPressed = true isDTimerRunning = false end, 150, 1 ) isDTimerRunning = true end function getS() isSKeyPressed = true isSTimerRunning = true end function getAStock() if isATimerRunning == true then killTimer ( aTimer ) isATimerRunning = false end isAKeyPressed = false end function getDStock() if isDTimerRunning == true then killTimer ( dTimer ) isDTimerRunning = false end isDKeyPressed = false end function getSStock() isSKeyPressed = false end bindKey ( "a", "down", getA ) bindKey ( "a", "up", getAStock ) bindKey ( "d", "down", getD ) bindKey ( "d", "up", getDStock ) bindKey ( "s", "down", getS ) bindKey ( "s", "up", getSStock ) function moving() vehicle = getPedOccupiedVehicle ( getLocalPlayer() ) if vehicle then attachElements ( centre, vehicle, ox, oy, oz ) attachElements ( point, vehicle, cx, cy, cz ) x, y, z = getElementPosition ( centre ) px, py, pz = getElementPosition ( point ) setCameraMatrix ( px, py, pz, x, y, z ) if isDKeyPressed == true then if cx < 1.5 then cx = cx + speed elseif cx > 1.5 then cx = 1.5 end elseif isAKeyPressed == true then if cx > -1.5 then cx = cx - speed elseif cx < -1.5 then cx = -1.5 end elseif cx > 0.1 then cx = cx - speed elseif cx < -0.1 then cx = cx + speed end if isDKeyPressed == true then if ox < 1 then ox = ox + speed elseif cx > 1 then ox = 1 end elseif isAKeyPressed == true then if ox > -1 then ox = ox - speed elseif ox < -1 then ox = -1 end elseif ox > 0.1 then ox = ox - speed elseif ox < -0.1 then ox = ox + speed end if isSKeyPressed == true then if oz > -1 then oz = oz - speed*2 end elseif oz < 1 then oz = oz + speed*2 end end end addEventHandler ( "onClientPreRender", root, moving ) 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