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