Jump to content

[HELP]: setElementRotation


Skraund

Recommended Posts

Posted

Hello, I have a resource airbrake with this code:

function putPlayerInPosition(timeslice)
	local cx,cy,cz,ctx,cty,ctz = getCameraMatrix()
	ctx,cty = ctx-cx,cty-cy
	timeslice = timeslice*0.1
	if getKeyState("num_7") then timeslice = timeslice*4 end
	if getKeyState("num_9") then timeslice = timeslice*0.25 end
	local mult = timeslice/math.sqrt(ctx*ctx+cty*cty)
	ctx,cty = ctx*mult,cty*mult
	if getKeyState("w") then abx,aby = abx+ctx,aby+cty end
	if getKeyState("s") then abx,aby = abx-ctx,aby-cty end
	if getKeyState("d") then abx,aby = abx+cty,aby-ctx end
	if getKeyState("a") then abx,aby = abx-cty,aby+ctx end
	if getKeyState("space") then abz = abz+timeslice end
	if getKeyState("lshift") then abz = abz-timeslice end
	setElementPosition(localPlayer,abx,aby,abz)
end

function toggleAirBrake()
	air_brake = not air_brake or nil
	if air_brake then
		abx,aby,abz = getElementPosition(localPlayer)
		addEventHandler("onClientPreRender",root,putPlayerInPosition)
	else
		abx,aby,abz = nil
		removeEventHandler("onClientPreRender",root,putPlayerInPosition)
	end
end
bindKey("num_0","down",toggleAirBrake)

But I do not know how to move the character to turn him in the direction where the camera is looking. Can someone help with this?

Posted
local cam = getCamera()
local _, _, cz = getElementRotation(cam)
local px, py, _ = getElementRotation(localPlayer)
setElementRotation(localPlayer, px, py, cz)

 

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...