Advertisement
ERROR_CODE

Player Follow Mouse

Dec 2nd, 2023 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.25 KB | None | 0 0
  1. script.Parent = game.StarterGui
  2.  
  3.  
  4. local RunSrv = game:GetService("RunService");
  5.  
  6. local Wrks = game:GetService("Workspace");
  7. local Plrs = game:GetService("Players");
  8.  
  9.  
  10.  
  11. local Ang = CFrame.Angles; 
  12. local aSin = math.asin;
  13. local aTan = math.atan;
  14.  
  15.  
  16.  
  17. local Cam = Wrks.CurrentCamera;
  18.  
  19. local Plr = Plrs.LocalPlayer;
  20. local Mouse = Plr:GetMouse();
  21. local Body = Wrks:WaitForChild(Plr.Name);
  22. local Head = Body:WaitForChild("Head");
  23. local Hum = Body:WaitForChild("Humanoid");
  24. local Core = Body:WaitForChild("HumanoidRootPart");
  25. local IsR6 = (Hum.RigType.Value==0);   
  26. local Trso = (IsR6 and Body:WaitForChild("Torso")) or Body:WaitForChild("UpperTorso");
  27. local Neck = (IsR6 and Trso:WaitForChild("Neck")) or Head:WaitForChild("Neck");
  28.  
  29. local MseGuide = true; 
  30. local Fctor = 1;   
  31.  
  32. local OrgnC0 = Neck.C0;
  33.  
  34.  
  35.  
  36. Neck.MaxVelocity = 1/3
  37.  
  38.  
  39.  
  40. coroutine.resume(coroutine.create(function()
  41.     while RunSrv.RenderStepped:wait() and Hum:GetState().Value~=15 do  
  42.         local CamCF = Cam.CoordinateFrame
  43.        
  44.         if ((IsR6 and Body["Torso"]) or Body["UpperTorso"])~=nil and Body["Head"]~=nil then
  45.             local TrsoLV = Trso.CFrame.lookVector
  46.             local HdPos = Head.CFrame.p
  47.             if ((IsR6 and Trso["Neck"]) or Head["Neck"])~=nil then 
  48.                 if Cam.CameraSubject:IsDescendantOf(Body) or Cam.CameraSubject:IsDescendantOf(Plr) then
  49.                     local Dist = nil;
  50.                     local Diff = nil;
  51.                     if not MseGuide then   
  52.                         Dist = (Head.CFrame.p-CamCF.p).magnitude
  53.                         Diff = Head.CFrame.Y-CamCF.Y
  54.                         if not IsR6 then   
  55.                             Neck.C0 = OrgnC0*Ang((aSin(Diff/Dist)*Fctor), -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y, 0)
  56.                         else    --[ R15s actually have the properly oriented Neck CFrame. ]
  57.                             Neck.C0 = OrgnC0*Ang(-(aSin(Diff/Dist)*Fctor), 0, -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y)
  58.                         end
  59.                     else
  60.                         local _, Point = Wrks:FindPartOnRay(Ray.new(Head.CFrame.p, Mouse.Hit.lookVector), Wrks, false, true)
  61.                         Dist = (Head.CFrame.p-Point).magnitude
  62.                         Diff = Head.CFrame.Y-Point.Y
  63.                         if not IsR6 then
  64.                             Neck.C0 = OrgnC0*Ang(-(aTan(Diff/Dist)*Fctor), (((HdPos-Point).Unit):Cross(TrsoLV)).Y*Fctor, 0)
  65.                         else
  66.                             Neck.C0 = OrgnC0*Ang((aTan(Diff/Dist)*Fctor), 0, (((HdPos-Point).Unit):Cross(TrsoLV)).Y*Fctor)
  67.                         end
  68.                     end
  69.                 end
  70.             end
  71.         end
  72.     end
  73. end))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement