Advertisement
Vzurxy

Untitled

Sep 8th, 2018
991
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. script.Parent = game.StarterGui
  2. --[ Head Follow Mouse/Camera ]--
  3.  
  4. --[ Services ]:
  5.  
  6. local RunSrv = game:GetService("RunService");
  7.  
  8. local Wrks = game:GetService("Workspace");
  9. local Plrs = game:GetService("Players");
  10.  
  11. --[ Pre-Funcs ]:
  12.  
  13. local Ang = CFrame.Angles; --[ Storing these as variables so I dont have to type them out. ]
  14. local aSin = math.asin;
  15. local aTan = math.atan;
  16.  
  17. --[ Constants ]:
  18.  
  19. local Cam = Wrks.CurrentCamera;
  20.  
  21. local Plr = Plrs.LocalPlayer;
  22. local Mouse = Plr:GetMouse();
  23. local Body = Wrks:WaitForChild(Plr.Name);
  24. local Head = Body:WaitForChild("Head");
  25. local Hum = Body:WaitForChild("Humanoid");
  26. local Core = Body:WaitForChild("HumanoidRootPart");
  27. local IsR6 = (Hum.RigType.Value==0); --[ Checking if the player is using the new Rig or the original. ]
  28. local Trso = (IsR6 and Body:WaitForChild("Torso")) or Body:WaitForChild("UpperTorso");
  29. local Neck = (IsR6 and Trso:WaitForChild("Neck")) or Head:WaitForChild("Neck"); --[ Once we know the Rig, we know what to find. ]
  30.  
  31. local MseGuide = true; --[ Useful with tools if true; camera tracking runs smoother however. ]
  32. local Fctor = 1; --[ 0: Negates tracking, 1: Relatively normal tracking, 2: Looks a little weird, just sayin'. ]
  33.  
  34. local OrgnC0 = Neck.C0; --[ Get the base C0 to manipulate off of. ]
  35.  
  36. --[ Setup ]:
  37.  
  38. Neck.MaxVelocity = 1/3
  39.  
  40. --[ Activation ]:
  41.  
  42. coroutine.resume(coroutine.create(function()
  43. while RunSrv.RenderStepped:wait() and Hum:GetState().Value~=15 do --[ Adding wait() here is the same as adding wait() later. ]
  44. local CamCF = Cam.CoordinateFrame
  45. --local MsePos = Mouse.Origin.p --[ Might do something with this in a future update... ]
  46. if ((IsR6 and Body["Torso"]) or Body["UpperTorso"])~=nil and Body["Head"]~=nil then --[ Check for the Torso and Head... ]
  47. local TrsoLV = Trso.CFrame.lookVector
  48. local HdPos = Head.CFrame.p
  49. if ((IsR6 and Trso["Neck"]) or Head["Neck"])~=nil then --[ Make sure the Neck still exists. ]
  50. if Cam.CameraSubject:IsDescendantOf(Body) or Cam.CameraSubject:IsDescendantOf(Plr) then
  51. local Dist = nil;
  52. local Diff = nil;
  53. if not MseGuide then --[ If not tracking the Mouse then get the Camera. ]
  54. Dist = (Head.CFrame.p-CamCF.p).magnitude
  55. Diff = Head.CFrame.Y-CamCF.Y
  56. if not IsR6 then --[ R6 and R15 Neck rotation C0s are different; R15: X axis inverted and Z is now the Y. ]
  57. Neck.C0 = OrgnC0*Ang((aSin(Diff/Dist)*Fctor), -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y, 0)
  58. else --[ R15s actually have the properly oriented Neck CFrame. ]
  59. Neck.C0 = OrgnC0*Ang(-(aSin(Diff/Dist)*Fctor), 0, -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y)
  60. end
  61. else
  62. local _, Point = Wrks:FindPartOnRay(Ray.new(Head.CFrame.p, Mouse.Hit.lookVector), Wrks, false, true)
  63. Dist = (Head.CFrame.p-Point).magnitude
  64. Diff = Head.CFrame.Y-Point.Y
  65. if not IsR6 then
  66. Neck.C0 = OrgnC0*Ang(-(aTan(Diff/Dist)*Fctor), (((HdPos-Point).Unit):Cross(TrsoLV)).Y*Fctor, 0)
  67. else
  68. Neck.C0 = OrgnC0*Ang((aTan(Diff/Dist)*Fctor), 0, (((HdPos-Point).Unit):Cross(TrsoLV)).Y*Fctor)
  69. end
  70. end
  71. end
  72. end
  73. end
  74. end
  75. end))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement