How would I know what direction the player is rotating in?

Hey there! I am trying to know what direction the player is rotating in (left or right) in first person, but I have no idea how to do it. This is probably super easy, but I just don’t understand.

Any help is appreciated!

1 Like

this is a localscript btw. works for any time the camera moves left or right.

local runService = game:GetService('RunService')
local camera = workspace.CurrentCamera 

local previousYOrientation = 0
local _, y, _ = camera.CFrame:ToEulerAnglesYXZ()

previousYOrientation = math.deg(y)

runService.RenderStepped:Connect(function()
	_, y, _ = camera.CFrame:ToEulerAnglesYXZ()
	local currentYOrientation = math.deg(y)
	if currentYOrientation > previousYOrientation then
		print('Player is looking towards the left!')
	elseif currentYOrientation < previousYOrientation then
		print('Player is looking towards the right!')
	end
	previousYOrientation = currentYOrientation
end)

For some reason this only prints left or right when I reach a threshold, not if the camera is actively moving left or right.

This will print is you are turning left or turning right, make sure CameraMode is in LockFirstPerson.

-- // Declared Services

local UserInputService = game:GetService("UserInputService");

-- // Functions

local function GetDeltaTurn()
	local NewDelta = UserInputService:GetMouseDelta()
	if NewDelta.X < 0 then
		warn("Turn Left")
	elseif NewDelta.X > 0 then
		warn("Turn Right")
	end
	return NewDelta
end

-- // Loops

while task.wait() do
	GetDeltaTurn()
end
1 Like

Another way you can get the direction the player is rotating is by roblox’s PlayerModule, you can call their Rot func in one of the Camera modules

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.