i am currently making a head movement script on a custom character. it works perfectly but it can turn its head all the way backwards. how can i make it so that the torso turns when the head angle exceeds 45 degrees like in minecraft? here is the script by the way
local uis = game:GetService("UserInputService")
local char = script.Parent
local head = char.Head
local cam = workspace.Camera
local viewport = game.ReplicatedStorage.Viewport:Clone()
local hand = char["Right Arm"]:Clone()
local neck = char.Torso:FindFirstChild("Neck")
local torso = char.Torso
local origin = neck.C0
hand.Parent = viewport
viewport.Parent = head
hand.CFrame = viewport.Arm.CFrame
hand.Anchored = true
viewport.Arm:Destroy()
cam.CameraSubject = head
function view()
hand.LocalTransparencyModifier = 0
viewport:SetPrimaryPartCFrame(cam.CFrame)
for i,v in pairs(char:GetChildren()) do
if v:IsA("Part") and v ~= head then
v.LocalTransparencyModifier = 0
end
end
end
function turn()
--i guess this is where i make the torso turn
end
function headmovement()
local adjust = torso.CFrame:ToObjectSpace(cam.CFrame)
local angle = adjust-adjust.Position
neck.C0 = origin*angle
end
function update()
turn()
view()
headmovement()
end
game:GetService("RunService").RenderStepped:Connect(update)
