How to rotate head (motor6d) away from camera within a 180 degree range?

https://gyazo.com/93f6eb61e6cb4e898bad9c273b356bff
Hi guys, today I’ve been tinkering around with head rotation with camera as a very nice piece of polish to add towards my rig. So far I have a script that replicates CFrame of a Motor6D’s (Neck’s) c0 to other players, but I don’t really know what to put in for the calculations of the rotation.

I want the head to rotate away from the camera within a 180 degree range, but so far most tutorials are adjusted for regular r6 rigs, and I’m not working with one here.

https://i.gyazo.com/288e4c5b1385949e58d05086ffbb32ed.gif

This is the closest I’ve gotten to the result so far, a gif showcasing another player’s head movement.

However, I want the head simply to move around it’s center, whilst not being able to turn 180 degrees like an owl, kind of like in this video (which I got the scripts from, with intent to modify them for my purposes): Server Side Head/Camera Movement (R6/R15) - Roblox (Remote Events and Tweening) - YouTube
How can I achieve this?

Here’s my client-side script so far, placed in starterCharacterScripts (Which handles the movement, server side script simply tells everyone else the cframe which is fired from this script):

local tweenService = game:GetService("TweenService")

local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer

local Character = Player.Character
local Root = Character:WaitForChild("HumanoidRootPart")
local Neck = Character:FindFirstChild("Neck", true)
local YOffset = Neck.C0.Y

local CFNew, CFAng = CFrame.new, CFrame.Angles
local asin = math.asin

game:GetService("RunService").RenderStepped:Connect(function()
    local CameraDirection = Root.CFrame:toObjectSpace(Camera.CFrame).lookVector
    if Neck then
		Neck.C0 = CFNew(0, YOffset, 0) * CFAng(3 * math.pi/2, 0, math.pi) * CFAng(0, 0, -asin(CameraDirection.x)) * CFAng(-asin(CameraDirection.y), 0, 0)
    end
end)

game.ReplicatedStorage.Remotes.Look.OnClientEvent:Connect(function(otherPlayer, neckCFrame)
	local Neck = otherPlayer.Character:FindFirstChild("Neck", true)
	
	if Neck then
		tweenService:Create(Neck, TweenInfo.new(.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0), {C0 = neckCFrame}):Play()
	end
end)

while wait(.2) do
	game.ReplicatedStorage.Remotes.Look:FireServer(Neck.C0)
end

i already made a head point to camera lookvector script:

local Plr = game.Players.LocalPlayer
local neck = Plr.Character.Torso.Neck
local camera = workspace.CurrentCamera

local hip = Plr.Character.Torso:WaitForChild("Right Hip")
local humanoid = Plr.Character.Humanoid

game:GetService("RunService").RenderStepped:Connect(function()
wait()
local theplace = Plr.Character.HumanoidRootPart.CFrame:toObjectSpace(camera.CFrame).lookVector

	local value = CFrame.new(0,1.025,0) * CFrame.Angles(math.asin(theplace.Y)+5,0,-math.asin(theplace.X)+84.75)
	
	neck.C0 = value
	
end)

although its only clientside and made for r6 you can try applying this kind of script to yours

I’m gonna try this out, I don’t know if it’ll work though since I need my object to rotate around it’s center. Will update you on result


this is what its supposed to look like before another unrelated script kicked in

66a2b234e7791d615887300945144c03
Yeah it’s a bit closer to what I need, but as you can see in the gif near the end, I get this weird rotation forwards and backwards kind of. Any idea on how to make it purely rotate around the center, since I know the formula/calculation makes it so that it pivots around where the ‘neck’ is on an r6 model.

if you want it to only rotate then replace the end with this:

	local value = CFrame.Angles(-math.asin(theplace.Y)+5,0,math.asin(theplace.X)+84.75)
	neck.C1 = value
	
end)

OMG! You’re a life saver! I’ve been struggling on this problem for about 3 hours now, since I can’t really grasp my head around CFrame rotation! Thank you so much.
8587dcfd85a755c40f2a3f1022319613