Advertisement
Guest User

Untitled

a guest
Jul 9th, 2018
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.58 KB | None | 0 0
  1. --[[
  2. [Head/Waist Follow Mouse/Camera Script.]
  3. [Works with both R6 and R15, lets you turn your character's head and waist towards your mouse/camera.]
  4. [Scripted by (Unknown), upgraded by OhHeyItsCory.]
  5. [I'm not sure who made the original script and the person I found it from definitely didn't make it.]
  6. [If you find the original creator, please let me know so I can properly credit them <3]
  7. [Anyways, here's a list of what I've added.]
  8. [Waist rotation. (Previously, only the head turned.)]
  9. [Tweening. (Basically, animating the rotation instead of instantly turning.)]
  10. [Full body rotation. (If set to true, rotates the entire body towards the mouse.)]
  11. [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!)]
  12. --]]
  13.  
  14. wait()
  15.  
  16. --[Pre-Funcs]:
  17.  
  18. local Ang = CFrame.Angles --[Storing these as variables so I dont have to type them out.]
  19. local aSin = math.asin
  20. local aTan = math.atan
  21.  
  22. --[Constants]:
  23.  
  24. local Cam = game.Workspace.CurrentCamera
  25.  
  26. local Plr = game.Players.LocalPlayer
  27. local Mouse = Plr:GetMouse()
  28. local Body = Plr.Character or Plr.CharacterAdded:wait()
  29. local Head = Body:WaitForChild("Head")
  30. local Hum = Body:WaitForChild("Humanoid")
  31. local Core = Body:WaitForChild("HumanoidRootPart")
  32. local IsR6 = (Hum.RigType.Value==0) --[Checking if the player is using R15 or R6.]
  33. local Trso = (IsR6 and Body:WaitForChild("Torso")) or Body:WaitForChild("UpperTorso")
  34. local Neck = (IsR6 and Trso:WaitForChild("Neck")) or Head:WaitForChild("Neck") --[Once we know the Rig, we know what to find.]
  35. local Waist = (not IsR6 and Trso:WaitForChild("Waist")) --[R6 doesn't have a waist joint, unfortunately.]
  36.  
  37. --[[
  38. [Whether rotation follows the camera or the mouse.]
  39. [Useful with tools if true, but camera tracking runs smoother.]
  40. --]]
  41. local MseGuide = false
  42. --[[
  43. [Whether the whole character turns to face the mouse.]
  44. [If set to true, MseGuide will be set to true and both HeadHorFactor and BodyHorFactor will be set to 0]
  45. --]]
  46. local TurnCharacterToMouse = false
  47. --[[
  48. [Horizontal and Vertical limits for head and body tracking.]
  49. [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.]
  50. --]]
  51. local HeadHorFactor = 1
  52. local HeadVertFactor = 0.6
  53. local BodyHorFactor = 0.5
  54. local BodyVertFactor = 0.4
  55.  
  56. --[[
  57. [How fast the body rotates.]
  58. [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.]
  59. [Setting this any higher than 1 causes weird glitchy shaking occasionally.]
  60. --]]
  61. local UpdateSpeed = 0.5
  62.  
  63. local NeckOrgnC0 = Neck.C0 --[Get the base C0 to manipulate off of.]
  64. local WaistOrgnC0 = (not IsR6 and Waist.C0) --[Get the base C0 to manipulate off of.]
  65.  
  66. --[Setup]:
  67.  
  68. Neck.MaxVelocity = 1/3
  69.  
  70. -- Activation]:
  71. if TurnCharacterToMouse == true then
  72. MseGuide = true
  73. HeadHorFactor = 0
  74. BodyHorFactor = 0
  75. end
  76.  
  77. game:GetService("RunService").RenderStepped:Connect(function()
  78. local CamCF = Cam.CoordinateFrame
  79. if ((IsR6 and Body["Torso"]) or Body["UpperTorso"])~=nil and Body["Head"]~=nil then --[Check for the Torso and Head...]
  80. local TrsoLV = Trso.CFrame.lookVector
  81. local HdPos = Head.CFrame.p
  82. if IsR6 and Neck or Neck and Waist then --[Make sure the Neck still exists.]
  83. if Cam.CameraSubject:IsDescendantOf(Body) or Cam.CameraSubject:IsDescendantOf(Plr) then
  84. local Dist = nil;
  85. local Diff = nil;
  86. if not MseGuide then --[If not tracking the Mouse then get the Camera.]
  87. Dist = (Head.CFrame.p-CamCF.p).magnitude
  88. Diff = Head.CFrame.Y-CamCF.Y
  89. if not IsR6 then --[R6 and R15 Neck rotation C0s are different; R15: X axis inverted and Z is now the Y.]
  90. Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang((aSin(Diff/Dist)*HeadVertFactor), -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y*HeadHorFactor, 0), UpdateSpeed/2)
  91. Waist.C0 = Waist.C0:lerp(WaistOrgnC0*Ang((aSin(Diff/Dist)*BodyVertFactor), -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y*BodyHorFactor, 0), UpdateSpeed/2)
  92. else --[R15s actually have the properly oriented Neck CFrame.]
  93. Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang(-(aSin(Diff/Dist)*HeadVertFactor), 0, -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y*HeadHorFactor),UpdateSpeed/2)
  94. end
  95. else
  96. local Point = Mouse.Hit.p
  97. Dist = (Head.CFrame.p-Point).magnitude
  98. Diff = Head.CFrame.Y-Point.Y
  99. if not IsR6 then
  100. Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang(-(aTan(Diff/Dist)*HeadVertFactor), (((HdPos-Point).Unit):Cross(TrsoLV)).Y*HeadHorFactor, 0), UpdateSpeed/2)
  101. Waist.C0 = Waist.C0:lerp(WaistOrgnC0*Ang(-(aTan(Diff/Dist)*BodyVertFactor), (((HdPos-Point).Unit):Cross(TrsoLV)).Y*BodyHorFactor, 0), UpdateSpeed/2)
  102. else
  103. Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang((aTan(Diff/Dist)*HeadVertFactor), 0, (((HdPos-Point).Unit):Cross(TrsoLV)).Y*HeadHorFactor), UpdateSpeed/2)
  104. end
  105. end
  106. end
  107. end
  108. end
  109. if TurnCharacterToMouse == true then
  110. Hum.AutoRotate = false
  111. Core.CFrame = Core.CFrame:lerp(CFrame.new(Core.Position, Vector3.new(Mouse.Hit.p.x, Core.Position.Y, Mouse.Hit.p.z)), UpdateSpeed / 2)
  112. else
  113. Hum.AutoRotate = true
  114. plr = game.Players.LocalPlayer
  115. mouse = plr:GetMouse()
  116. part = nil
  117. bp = nil
  118. particles = nil
  119. function clerp(a,b,c,d)
  120. for i = 0,d,.01 do
  121. a.CFrame = CFrame.new(b:lerp(c,i))
  122. wait()
  123. end
  124. end
  125. function slerp(a2,b2,c2,d2)
  126. for i2 = 0,d2,.01 do
  127. a2.CFrame = CFrame.new(b2:lerp(c2,i2))
  128. wait()
  129. end
  130. end
  131. mouse.KeyDown:connect(function(key)
  132. if key == "e" and plr.Character.Parent == workspace then
  133. plr.Character.Parent = workspace.Camera
  134. plr.Character.Archivable = true
  135. Instance.new("ForceField",plr.Character).Visible = false
  136. for y,t in pairs(plr.Character:GetChildren()) do
  137. if t:IsA("Part") and t.Name ~= "HumanoidRootPart" then
  138. t.Transparency = 1
  139. if t.Name == "Head" and t:FindFirstChild("face") then
  140. t.face.Transparency = 1
  141. end
  142. elseif t:IsA("Accessory") and t:FindFirstChild("Handle") then
  143. t.Handle.Transparency = 1
  144. end
  145. end
  146. elseif key == "z" and plr.Character.Parent == workspace.Camera and part == nil then
  147. plr.Character.Torso.CFrame = CFrame.new(Vector3.new(mouse.hit.p.X,mouse.hit.p.Y+1.5,mouse.hit.p.Z),plr.Character.Torso.CFrame.p)
  148. elseif key == "x" and plr.Character.Parent == workspace.Camera and part == nil then
  149. if plr.Character.Torso.Anchored == true then
  150. for y,t in pairs(plr.Character:GetChildren()) do
  151. if t:IsA("Part") then
  152. t.Anchored = false
  153. end
  154. end
  155. else
  156. for y,t in pairs(plr.Character:GetChildren()) do
  157. if t:IsA("Part") then
  158. t.Anchored = true
  159. end
  160. end
  161. end
  162. elseif key == "c" and plr.Character.Parent == workspace.Camera and part ~= nil then
  163. local clone = part:Clone()
  164. clone.Parent = workspace
  165. clone.Anchored = false
  166. clone:ClearAllChildren()
  167. clone.CanCollide = true
  168. bp.Parent = clone
  169. particles.Parent = clone
  170. if part.Parent:FindFirstChildOfClass("Humanoid") then
  171. part.Parent:FindFirstChildOfClass("Humanoid").PlatformStand = false
  172. end
  173. part:Destroy()
  174. part = clone
  175. elseif key == "t" and plr.Character.Parent == workspace.Camera and part == nil then
  176. plr.Character.Parent = workspace
  177. plr.Character.Archivable = false
  178. plr.Character:FindFirstChildOfClass("ForceField"):Remove()
  179. for y,t in pairs(plr.Character:GetChildren()) do
  180. if t:IsA("Part") and t.Name ~= "HumanoidRootPart" then
  181. t.Transparency = 0
  182. if t.Name == "Head" and t:FindFirstChild("face") then
  183. t.face.Transparency = 0
  184. end
  185. elseif t:IsA("Accessory") and t:FindFirstChild("Handle") then
  186. t.Handle.Transparency = 0
  187. end
  188. end
  189. end
  190. end)
  191. mouse.Button1Down:connect(function()
  192. if plr.Character.Parent == workspace.Camera then
  193. if mouse ~= nil then
  194. if mouse.Target ~= nil then
  195. part = mouse.Target
  196. bp = Instance.new("BodyPosition",part)
  197. bp.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
  198. bp.Position = part.Position
  199. particles = Instance.new("ParticleEmitter",part)
  200. particles.Color = ColorSequence.new(Color3.new(0,0,0))
  201. particles.Size = NumberSequence.new(1)
  202. particles.Texture = "rbxassetid://292289455"
  203. particles.VelocitySpread = 360
  204. particles.Speed = NumberRange.new(0)
  205. particles.RotSpeed = NumberRange.new(0)
  206. particles.Rotation = NumberRange.new(0)
  207. particles.Rate = 250
  208. particles.Lifetime = NumberRange.new(.2,.4)
  209. particles.Transparency = NumberSequence.new({NumberSequenceKeypoint.new(0,1,0),NumberSequenceKeypoint.new(.12,.688,0),NumberSequenceKeypoint.new(.891,.887,0),NumberSequenceKeypoint.new(1,1,0)})
  210. dwn = true
  211. end
  212. end
  213. while dwn == true do
  214. wait()
  215. bp.Position = mouse.hit.p
  216. if part then
  217. if part.Parent:FindFirstChildOfClass("Humanoid") then
  218. part.Parent:FindFirstChildOfClass("Humanoid").PlatformStand = true
  219.  
  220.  
  221.  
  222. mouse.Button1Up:connect(function()
  223. dwn = false
  224. if part then if part.Parent:FindFirstChildOfClass("Humanoid") then part.Parent:FindFirstChildOfClass("Humanoid").PlatformStand = false end part = nil end
  225. if bp then bp:Destroy() end
  226. if particles then particles:Destroy() end
  227. end)
  228. base = Instance.new("ScreenGui",plr.PlayerGui)
  229. bbg = Instance.new("BillboardGui",plr.Character.Head)
  230. bbg.Size = UDim2.new(0,200,0,50)
  231. bbg.StudsOffset = Vector3.new(0,3,0)
  232. bbgTl = Instance.new("TextLabel",bbg)
  233. bbgTl.BackgroundTransparency = 1
  234. bbgTl.Size = UDim2.new(10,0,1,0)
  235. bbgTl.Position = UDim2.new(-4.5,0,0,0)
  236. bbgTl.Font = "Code"
  237. bbgTl.Text = " "
  238. bbgTl.TextSize = 25
  239. bbgTl.TextStrokeColor3 = Color3.new(1,1,1)
  240. bbgTl.TextColor3 = Color3.new(0,0,0)
  241. bbgTl.TextStrokeTransparency = 0
  242. bbgTl.TextWrapped = true
  243. plr.Chatted:connect(function(msg)
  244. bbgTl.Text = msg
  245. wait(5)
  246. if bbgTl.Text == msg then
  247. bbgTl.Text = " "
  248. end
  249. end)
  250. touchCounter = 0
  251. while wait() do
  252. if plr.Character.Parent == workspace.Camera then
  253. local c = plr.Character:Clone()
  254. c:MakeJoints()
  255. for y,t in pairs(c:GetChildren()) do
  256. if t:IsA("Part") then
  257. t.CanCollide = false
  258. t.Anchored = true
  259. t.Transparency = .5
  260. t.TopSurface = "Smooth"
  261. t.BottomSurface = "Smooth"
  262. t.RightSurface = "Smooth"
  263. t.LeftSurface = "Smooth"
  264. t.FrontSurface = "Smooth"
  265. t.BackSurface = "Smooth"
  266. t.BrickColor = BrickColor.new("Really black")
  267. if t.Name == "Head" and t:FindFirstChild("face") then
  268. t.face:Remove()
  269. elseif t.Name == "Torso" and t:FindFirstChild("roblox") then
  270. t.roblox:Remove()
  271. elseif t.Name == "HumanoidRootPart" then
  272. t:Remove()
  273. end
  274. else
  275. t:Remove()
  276. end
  277. end
  278. c.Parent = workspace
  279. game.Debris:AddItem(c,.05)
  280. end
  281. end
  282. end
  283. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement