How to check what direction is the player looking

I am trying to check if the player is looking by the X, Y or Z axis. I need to know how to do this in either the client or the server.

3 Likes

You mean you want to get player look orientation? i think you should just get player’s head orientation.

Use LookVector == x,y,z

Character.HumanoidRootPart.CFrame.LookVector

No I mean what axis are they looking towards. And even if I try that the head does not move with the clients camera.

I’m sorry, What do you mean by that?

oh, soo you want camera look vector? then you should use workspace.currentCamera.CFrame.LookVector

How would I do that? Would I check which axis is greater (if it returns a Vector3)?

(nvm I did some more research)

i think you will need to get orientation from camera CFrame. This page should help you do it:
https://developer.roblox.com/en-us/api-reference/datatype/CFrame

then you should do something like this:
character.HumanoidRootPart.Orientation - [the camera Orientation].
Then you should change all negative numbers to positive.

1 Like
local run = game:GetService("RunService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")

run.RenderStepped:Connect(function()
	if hrp.CFrame.LookVector.X > 0.5 then
		print("Facing north.")
	elseif hrp.CFrame.LookVector.X < -0.5 then
		print("Facing south.")
	end
	
	if hrp.CFrame.RightVector.X < -0.5 then
		print("Facing east.")
	elseif hrp.CFrame.RightVector.X > 0.5 then
		print("Facing west.")
	end
end)

Never mind, you’re asking for direction of the character’s position not movement direction.

9 Likes