Sorry if the title sounds a bit obscure, it’s hard to describe this. Basically I’m trying to make it so if your camera, relative to the player’s HumanoidRootPart is past 90 degrees. I’ve managed to get it working some what, but when the character is oriented at certain angles, being 5 degrees away from the HumanoidRootPart’s angle returns numbers from around 340 to 360 instead.
The use case is for tilting the player’s head at the X angle for looking up and down. When they are past 90 degrees (looking at their character’s face) I want it to face towards the camera instead of towards the ground. (and when they are facing the back of their character, they face towards where the camera is looking)
ReferencePart.CFrame = Camera.CFrame
local HeadAngle
local CameraHeadOffset = math.abs(ReferencePart.Orientation.Y-Character.HumanoidRootPart.Orientation.Y)
if CameraHeadOffset < 90 then
HeadAngle = math.rad(ReferencePart.Orientation.X)
else
HeadAngle = -math.rad(ReferencePart.Orientation.X)
end
Just a thought, but have you looked into perhaps using the Dot Product of the Camera’s lookVector and the character’s torso’s lookVector? (You can nullify the Y components of the vectors to just get the vectors on the X/Z plane, then use the dot product to see whether the camera is facing the face of the character or the back of it)
So I’ve tried a few things but it seems to only depend on Camera.Orientation and turning the character did nothing. I might try doing magnitude and see how that goes.
The part is just for getting an orientation from the CFrame because CFrame:ToOrientation wasn’t working for me. The part’s orientation is set every frame.
After running a quick test in studio, it seems to work (I simply printed dot every frame. If the result is positive, the camera is behind the head, otherwise it is infront of the head). You can change Character.Head.CFrame to whichever part of the character you want to check from.