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