How can I tell if the player is looking to the Left or Right of their character

I’m coding a custom movement system to give characters a turn radius wherein they turn slowly to face the same direction as the camera. If they want to turn, they will walk forward while slowly turning to face that direction.

I could do this by finding out if the player is facing to the right or left of their character and then slowly rotating their character clockwise or counterclockwise until they are facing the same direction as the camera (thats what I’m planning but any other suggestions welcome)

But I need to figure out what direction they are facing relative to what direction the character is facing

How do I find this?


3 Likes

Cross product, with a position in front of the camera using camera.Position + camera lookvector*1000

2 Likes

thank you, I’m trying to do something with that but I don’t understand.


Is this what you mean? I’ve done this but don’t see any association with whether the player is looking left or right

You can also transform the camera cframe lookvector to the character head cframe’s object space. Then check whether the X component of the resulting vector is positive or negative.

Example as a localscript in game.StarterGui:

while true do
	wait(0.1)
	local camCF = workspace.CurrentCamera.CFrame
	local playerCF = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame
	local vector = playerCF:ToObjectSpace(camCF).LookVector
	if (vector.X == 0) then
		print("looking straight")
	elseif (vector.X < 0) then
		print("looking left")
	else
		print("looking right")
	end
end
3 Likes

that works, thank you so much!