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
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:
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)
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.