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)