Help in rotating head to camera direction

i am trying to rotate head to camera front direction but its just not correct

local character = script.Parent
local currentCamera = workspace.CurrentCamera :: Camera

local neck = character:WaitForChild("Torso"):WaitForChild("Neck") :: Motor6D

local runservice = game:GetService("RunService")

runservice.PreRender:Connect(function()
	local cameraCFrame = currentCamera.CFrame
	local front = neck.Parent.CFrame:VectorToObjectSpace(cameraCFrame.LookVector)
	neck.C0 = CFrame.new(neck.C0.Position) * CFrame.Angles(math.asin(front.Y), math.atan2(front.X, -front.Z), 0)
end)


i have searched for other solutions but does not have knowledgeable answers to infer this topic

im using an r6 character

Try this instead:

neck.C0 = CFrame.lookAlong(neck.C0.Position, cameraCFrame.LookVector)

this aligned the -UpVector of the head to the camera direction and not LookVector

You can just rotate it by 90 degrees on either the X or Z axis negatively or positively, I’m not sure which one since the head is a cylinder. Just try all of them and see which one works:

neck.C0 = CFrame.lookAlong(neck.C0.Position, cameraCFrame.LookVector)
  -- 1: * CFrame.Angles(math.pi / 2, 0, 0)
  -- 2: * CFrame.Angles(-math.pi / 2, 0, 0)
  -- 3: * CFrame.Angles(0, 0, math.pi / 2)
  -- 4: * CFrame.Angles(0, 0, -math.pi / 2)

I just wrote this code. It looks kind of cursed, but the head looks along the camera lookvector. (I used the camera’s rotation instead of lookvector since I have to convert it to a rotation anyways, it does the same thing still)

local character = script.Parent
local currentCamera = workspace.CurrentCamera :: Camera

local torso = character:WaitForChild("Torso") :: BasePart

local neck = character:WaitForChild("Torso"):WaitForChild("Neck") :: Motor6D
local defaultNeckAngle = neck.C0.Rotation

local runservice = game:GetService("RunService")

runservice.PreRender:Connect(function()
	local cameraAngle = currentCamera.CFrame.Rotation
	local cameraAngleRelativeToHead = torso.CFrame.Rotation:Inverse() * cameraAngle
	
	neck.C0 = CFrame.new(neck.C0.Position) * cameraAngleRelativeToHead * defaultNeckAngle
end)

Is this what you wanted?

It is not that cursed, but using the full CFrame rotation and inverting it is a bit heavy for every frame. You could just use the LookVector and transform it into the torso’s space to get the angles directly, which avoids the extra matrix math.