Recently I have been messing around with CFraming, and managed to make the heads of player characters to rotate along with the LookVector of their camera. But I only got it working vertically, and I couldn’t find a way to make the horizontal rotation work.
Here’s a snippet of the code that modifies the C0 of the chararacter’s Neck along with one of my attempts:
local NeckC0 = CFrame.new(0, 1, 0, -1, 0, 0, 0, 0, 1, 0, 1, 0)
local ThetaY = math.asin(Camera.CFrame.LookVector.Y)
local ThetaX = math.asin(Camera.CFrame.LookVector.X)
local ThetaZ = math.asin(Camera.CFrame.LookVector.Z)
--the issue
local NeckAngle = NeckC0 * CFrame.fromEulerAnglesYXZ(ThetaY * -0.5, 0, ThetaX or ThetaZ)
I also tried multiplying, diving and summing, yet no good results…
Well you would need to align the look vector into the same plane as the characters walk surface, assuming it’s the XZ plane which the character usually is when it’s walking upright you can just multiply where it’s looking by a vector of (1,0,1) to remove the y axis like so:
Also my personal advice is to not use euler angles, it gets rly complicated with the z axis being the roll of the CFrame (yaw,pitch,roll). You can use CFrame from axis angle to rotate along an axis instead which can be defined more easily.
Thanks for the advice about FromAxisAngle, I found Euler Angles a bit confusing so this really helps, also I just ended up finding a solution that got the Neck rotation working correctly from a youtube tutorial about the same thing I have been trying to do!
Oh, I almost forgot! Thank you for the method of CFrame orientation, I suppose it could use it for something else.