Advertisement
Guest User

Roblox Optimised Head Follow

a guest
Dec 5th, 2019
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.14 KB | None | 0 0
  1. local CFNew, CFAng, CFtoObjectSpace = CFrame.new, CFrame.Angles, CFrame.new( ).toObjectSpace
  2. local asin, pi, hpi = math.asin, math.pi, math.pi / 2
  3.  
  4. local Plr= game.Players.LocalPlayer
  5.  
  6. game:GetService("RunService").RenderStepped:Connect(function()
  7.     if Plr.Character then
  8.         local Root, Neck, Humanoid, Camera = Plr.Character:FindFirstChild("HumanoidRootPart"), Plr.Character:FindFirstChild("Neck", true), Plr.Character:FindFirstChild("Humanoid"), workspace.CurrentCamera
  9.         if Root and Neck and Humanoid and Camera.CameraSubject then
  10.             local R6 = Humanoid.RigType == Enum.HumanoidRigType.R6
  11.             if Camera.CameraSubject.Parent == Plr.Character then
  12.                 local CameraDirection = CFtoObjectSpace(Root.CFrame, Camera.CFrame).lookVector.unit
  13.                 Neck.C0 = CFNew(Neck.C0.p) * CFAng(0, -asin(CameraDirection.x), 0) * (R6 and CFAng(-hpi + asin(CameraDirection.y), 0, pi) or CFAng(asin(CameraDirection.y), 0, 0))
  14.             else
  15.                 Neck.C0 = R6 and CFNew(Neck.C0.p) * CFAng(-hpi, 0, pi) or CFNew(Neck.C0.p)
  16.             end
  17.         end
  18.     end
  19. end)
  20.  
  21. -- Made by Youtube.com/c/StillwaterYT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement