Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.94 KB | None | 0 0
  1. - Thanks for using Mod2S by NopeUsername
  2. local functions = {}
  3. function sandbox(script, func)
  4. local OldEnv = getfenv(func)
  5.  
  6. local NewEnv = setmetatable({}, {
  7. __index = function(self,k)
  8. if k == "script" then
  9. return script
  10. else
  11. return OldEnv[k]
  12. end
  13. end,
  14. })
  15.  
  16. setfenv(func, NewEnv)
  17. return func
  18. end
  19.  
  20. local mas = Instance.new("Model", game:GetService("Lighting"))
  21. -- DECLARING VARIABLES"
  22.  
  23. local FollowMouseCameraScriptStarterGui = Instance.new("LocalScript")
  24.  
  25. -- SETTING PROPERTIES
  26.  
  27. table.insert(functions, sandbox(FollowMouseCameraScriptStarterGui, function()
  28. --[[
  29. [Head/Waist Follow Mouse/Camera Script.]
  30. [Works with both R6 and R15, lets you turn your character's head and waist towards your mouse/camera.]
  31. [Scripted by (Unknown), upgraded by OhHeyItsCory.]
  32. [I'm not sure who made the original script and the person I found it from definitely didn't make it.]
  33. [If you find the original creator, please let me know so I can properly credit them <3]
  34. [Anyways, here's a list of what I've added.]
  35. [Waist rotation. (Previously, only the head turned.)]
  36. [Tweening. (Basically, animating the rotation instead of instantly turning.)]
  37. [Full body rotation. (If set to true, rotates the entire body towards the mouse.)]
  38. [Specific rotation limits. (The original script used one variable to set the limits of both horizontal and vertical rotation, now there's variables for both limits!)]
  39. --]]
  40.  
  41. wait()
  42.  
  43. --[Pre-Funcs]:
  44.  
  45. local Ang = CFrame.Angles --[Storing these as variables so I dont have to type them out.]
  46. local aSin = math.asin
  47. local aTan = math.atan
  48.  
  49. --[Constants]:
  50.  
  51. local Cam = game.Workspace.CurrentCamera
  52.  
  53. local Plr = game.Players.LocalPlayer
  54. local Mouse = Plr:GetMouse()
  55. local Body = Plr.Character or Plr.CharacterAdded:wait()
  56. local Head = Body:WaitForChild("Head")
  57. local Hum = Body:WaitForChild("Humanoid")
  58. local Core = Body:WaitForChild("HumanoidRootPart")
  59. local IsR6 = (Hum.RigType.Value==0) --[Checking if the player is using R15 or R6.]
  60. local Trso = (IsR6 and Body:WaitForChild("Torso")) or Body:WaitForChild("UpperTorso")
  61. local Neck = (IsR6 and Trso:WaitForChild("Neck")) or Head:WaitForChild("Neck") --[Once we know the Rig, we know what to find.]
  62. local Waist = (not IsR6 and Trso:WaitForChild("Waist")) --[R6 doesn't have a waist joint, unfortunately.]
  63.  
  64. --[[
  65. [Whether rotation follows the camera or the mouse.]
  66. [Useful with tools if true, but camera tracking runs smoother.]
  67. --]]
  68. local MseGuide = false
  69. --[[
  70. [Whether the whole character turns to face the mouse.]
  71. [If set to true, MseGuide will be set to true and both HeadHorFactor and BodyHorFactor will be set to 0]
  72. --]]
  73. local TurnCharacterToMouse = false
  74. --[[
  75. [Horizontal and Vertical limits for head and body tracking.]
  76. [Setting to 0 negates tracking, setting to 1 is normal tracking, and setting to anything higher than 1 goes past real life head/body rotation capabilities.]
  77. --]]
  78. local HeadHorFactor = 1
  79. local HeadVertFactor = 0.6
  80. local BodyHorFactor = 0.5
  81. local BodyVertFactor = 0.4
  82.  
  83. --[[
  84. [How fast the body rotates.]
  85. [Setting to 0 negates tracking, and setting to 1 is instant rotation. 0.5 is a nice in-between that works with MseGuide on or off.]
  86. [Setting this any higher than 1 causes weird glitchy shaking occasionally.]
  87. --]]
  88. local UpdateSpeed = 0.5
  89.  
  90. local NeckOrgnC0 = Neck.C0 --[Get the base C0 to manipulate off of.]
  91. local WaistOrgnC0 = (not IsR6 and Waist.C0) --[Get the base C0 to manipulate off of.]
  92.  
  93. --[Setup]:
  94.  
  95. Neck.MaxVelocity = 1/3
  96.  
  97. -- Activation]:
  98. if TurnCharacterToMouse == true then
  99. MseGuide = true
  100. HeadHorFactor = 0
  101. BodyHorFactor = 0
  102. end
  103.  
  104. game:GetService("RunService").RenderStepped:Connect(function()
  105. local CamCF = Cam.CoordinateFrame
  106. if ((IsR6 and Body["Torso"]) or Body["UpperTorso"])~=nil and Body["Head"]~=nil then --[Check for the Torso and Head...]
  107. local TrsoLV = Trso.CFrame.lookVector
  108. local HdPos = Head.CFrame.p
  109. if IsR6 and Neck or Neck and Waist then --[Make sure the Neck still exists.]
  110. if Cam.CameraSubject:IsDescendantOf(Body) or Cam.CameraSubject:IsDescendantOf(Plr) then
  111. local Dist = nil;
  112. local Diff = nil;
  113. if not MseGuide then --[If not tracking the Mouse then get the Camera.]
  114. Dist = (Head.CFrame.p-CamCF.p).magnitude
  115. Diff = Head.CFrame.Y-CamCF.Y
  116. if not IsR6 then --[R6 and R15 Neck rotation C0s are different; R15: X axis inverted and Z is now the Y.]
  117. Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang((aSin(Diff/Dist)*HeadVertFactor), -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y*HeadHorFactor, 0), UpdateSpeed/2)
  118. Waist.C0 = Waist.C0:lerp(WaistOrgnC0*Ang((aSin(Diff/Dist)*BodyVertFactor), -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y*BodyHorFactor, 0), UpdateSpeed/2)
  119. else --[R15s actually have the properly oriented Neck CFrame.]
  120. Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang(-(aSin(Diff/Dist)*HeadVertFactor), 0, -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y*HeadHorFactor),UpdateSpeed/2)
  121. end
  122. else
  123. local Point = Mouse.Hit.p
  124. Dist = (Head.CFrame.p-Point).magnitude
  125. Diff = Head.CFrame.Y-Point.Y
  126. if not IsR6 then
  127. Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang(-(aTan(Diff/Dist)*HeadVertFactor), (((HdPos-Point).Unit):Cross(TrsoLV)).Y*HeadHorFactor, 0), UpdateSpeed/2)
  128. Waist.C0 = Waist.C0:lerp(WaistOrgnC0*Ang(-(aTan(Diff/Dist)*BodyVertFactor), (((HdPos-Point).Unit):Cross(TrsoLV)).Y*BodyHorFactor, 0), UpdateSpeed/2)
  129. else
  130. Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang((aTan(Diff/Dist)*HeadVertFactor), 0, (((HdPos-Point).Unit):Cross(TrsoLV)).Y*HeadHorFactor), UpdateSpeed/2)
  131. end
  132. end
  133. end
  134. end
  135. end
  136. if TurnCharacterToMouse == true then
  137. Hum.AutoRotate = false
  138. Core.CFrame = Core.CFrame:lerp(CFrame.new(Core.Position, Vector3.new(Mouse.Hit.p.x, Core.Position.Y, Mouse.Hit.p.z)), UpdateSpeed / 2)
  139. else
  140. Hum.AutoRotate = true
  141. end
  142. end)
  143. end))
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151. for i,v in ipairs(functions) do
  152. spawn(function()
  153. pcall(v)
  154. end)
  155. end
  156.  
  157. for i,v in ipairs(mas:GetChildren()) do
  158. v.Parent = workspace
  159. end
  160. mas:Destroy()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement