Hey there! I’m trying to make a script that prints “Left” or “Right” depending on if the camera is looking left or right from the HumanoidRootPart while in first person and the HumanoidRootPart rotation is locked.
The script (Local):
if cam.CFrame.Rotation.Y < humanoid.RootPart.CFrame.Rotation.Y then
print("Left")
elseif cam.CFrame.Rotation.Y > humanoid.RootPart.CFrame.Rotation.Y then
print("Right")
end
It’s all inside of a while loop.
Any help is appreciated!
Hey, I think you should look into LookVectors for such an application. A VERY Basic implementation that i whipped out in 2 minutes is
local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
while true do
local camLook = cam.CFrame.LookVector
local playerLook = humanoid.RootPart.CFrame.LookVector
local DotVec = (playerLook:Dot(camLook))
if DotVec > 0 and DotVec < 0.5 then
print("Right")
elseif DotVec >= 0.5 and DotVec <= 1 then
print("Left")
end
task.wait(0.1)
end
The DotVector seems to print the same thing in both directions. It prints 0 when I look left, and 0 when I look right. I haven’t used :Dot before, but it doesn’t seem like it can really tell if I’m looking left or right, it just tells me if I’m at a right angle.