Jump to content

[Help] How can I increase the speed of rotation of the vehicle?


rubend10s

Recommended Posts

 

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 by rubend10s
Link to comment

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 by rubend10s
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...