Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR LUA

roblox rotate head with camera

--Lua/Roblox
--Put this in starterplayerscripts as a localscript

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

local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
repeat wait() until Player.Character
local Character = Player.Character
local Root = Character:WaitForChild("HumanoidRootPart")
local Neck = Character:FindFirstChild("Neck", true)
local YOffset = Neck.C0.Y
game:GetService("RunService").RenderStepped:Connect(function()
    local CameraDirection = Root.CFrame:toObjectSpace(Camera.CFrame).lookVector.unit
    if Neck then
        Neck.C0 = CFNew(0, YOffset, 0) * CFAng(0, -asin(CameraDirection.x), 0) * CFAng(asin(CameraDirection.y), 0, 0)
    end
end)
 
PREVIOUS NEXT
Tagged: #roblox #rotate #head #camera
ADD COMMENT
Topic
Name
4+7 =