rubend10s Posted February 4, 2020 Share Posted February 4, 2020 (edited) I was thinking of something like this to start function increaseRotationFunction() if getKeyState( "arrow_u" ) == true or getKeyState( "arrow_d" ) == true or getKeyState( "arrow_l" ) == true or getKeyState( "arrow_r" ) == true then local vehicle = getPedOccupiedVehicle(getLocalPlayer()) -- and i dont know end end addEventHandler("onClientRender",getRootElement(),increaseRotationFunction) and then use something like setElementAngularVelocity and getElementAngularVelocity I tried this but it didn't work too well function increaseRotationFunction() if getKeyState( "arrow_u" ) == true or getKeyState( "arrow_d" ) == true or getKeyState( "arrow_l" ) == true or getKeyState( "arrow_r" ) == true then local vehicle = getPedOccupiedVehicle(getLocalPlayer()) local avx, avy, avz = getElementAngularVelocity(vehicle) setElementAngularVelocity ( vehicle, avx * 2, avy * 2, avz * 2 ) end end addEventHandler("onClientRender",getRootElement(),increaseRotationFunction) Edited February 4, 2020 by rubend10s Link to comment
rubend10s Posted February 4, 2020 Author Share Posted February 4, 2020 (edited) I think I did it, it looks good 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 arrow_u_function() local vehicle = getPedOccupiedVehicle(getLocalPlayer()) local tx, ty, tz = getPositionFromElementOffset(vehicle,1,0,0) local avx, avy, avz = getElementAngularVelocity(vehicle) local vx,vy,vz = getElementPosition( vehicle ) setElementAngularVelocity ( vehicle, avx - 0.1 * (tx - vx), avy - 0.1 * (ty - vy), avz - 0.1 * (tz - vz) ) end function arrow_d_function() local vehicle = getPedOccupiedVehicle(getLocalPlayer()) local tx, ty, tz = getPositionFromElementOffset(vehicle,1,0,0) local avx, avy, avz = getElementAngularVelocity(vehicle) local vx,vy,vz = getElementPosition( vehicle ) setElementAngularVelocity ( vehicle, avx + 0.1 * (tx - vx), avy + 0.1 * (ty - vy), avz + 0.1 * (tz - vz) ) end function arrow_l_function() local vehicle = getPedOccupiedVehicle(getLocalPlayer()) local tx, ty, tz = getPositionFromElementOffset(vehicle,0,1,0) local avx, avy, avz = getElementAngularVelocity(vehicle) local vx,vy,vz = getElementPosition( vehicle ) setElementAngularVelocity ( vehicle, avx - 0.1 * (tx - vx), avy - 0.1 * (ty - vy), avz - 0.1 * (tz - vz) ) end function arrow_r_function() local vehicle = getPedOccupiedVehicle(getLocalPlayer()) local tx, ty, tz = getPositionFromElementOffset(vehicle,0,1,0) local avx, avy, avz = getElementAngularVelocity(vehicle) local vx,vy,vz = getElementPosition( vehicle ) setElementAngularVelocity ( vehicle, avx + 0.1 * (tx - vx), avy + 0.1 * (ty - vy), avz + 0.1 * (tz - vz) ) end bindKey ( "arrow_u","down", arrow_u_function) bindKey ( "arrow_d","down", arrow_d_function) bindKey ( "arrow_l","down", arrow_l_function) bindKey ( "arrow_r","down", arrow_r_function) Edited February 4, 2020 by rubend10s 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