Advertisement
Animescapetower

Player Camera Looking Motivator[VOID]

May 24th, 2018
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.38 KB | None | 0 0
  1. --Converted with ttyyuu12345's model to script plugin v4
  2. function sandbox(var,func)
  3. local env = getfenv(func)
  4. local newenv = setmetatable({},{
  5. __index = function(self,k)
  6. if k=="script" then
  7. return var
  8. else
  9. return env[k]
  10. end
  11. end,
  12. })
  13. setfenv(func,newenv)
  14. return func
  15. end
  16. cors = {}
  17. mas = Instance.new("Model",game:GetService("Lighting"))
  18. LocalScript0 = Instance.new("LocalScript")
  19. RemoteEvent1 = Instance.new("RemoteEvent")
  20. Script2 = Instance.new("Script")
  21. LocalScript3 = Instance.new("LocalScript")
  22. RemoteEvent4 = Instance.new("RemoteEvent")
  23. LocalScript3.Name = "Client"
  24. LocalScript3.Parent = Script2
  25. table.insert(cors,sandbox(LocalScript3,function()
  26. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  27. wait(.2) -- Local Scripts can be really annoying sometimes.
  28.  
  29. player = game.Players.LocalPlayer
  30. c = workspace.CurrentCamera
  31. rs = game:GetService("RunService")
  32.  
  33. char = player.Character or player.CharacterAdded:wait()
  34.  
  35. while not char:IsDescendantOf(game) do
  36. wait(.75)
  37. end
  38.  
  39. humanoid = char:WaitForChild("Humanoid")
  40. head = char:WaitForChild("Head")
  41. torso = char:WaitForChild("Torso")
  42. root = char:WaitForChild("HumanoidRootPart")
  43. rootJ = root:WaitForChild("RootJoint")
  44. lhip = torso:WaitForChild("Left Hip")
  45. lshoulder = torso:WaitForChild("Left Shoulder")
  46. rshoulder = torso:WaitForChild("Right Shoulder")
  47. rhip = torso:WaitForChild("Right Hip")
  48. neck = torso:WaitForChild("Neck")
  49.  
  50. waveScale = 0
  51. scaleIncrement = 0.05
  52. lastY = 0
  53. pi2 = math.pi*2
  54.  
  55. offStates = {"Jumping","PlatformStanding","Ragdoll","Seated","FallingDown","FreeFalling","GettingUp","Swimming"}
  56. onStates = {"Running","Climbing"}
  57.  
  58. active = false
  59. rs = game:GetService("RunService")
  60. connections = {}
  61.  
  62. server = script.Parent
  63. updateY = server:WaitForChild("UpdateY")
  64.  
  65. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  66.  
  67. RIG = {
  68. [rootJ] =
  69. {
  70. C0 = rootJ.C0 * CFrame.new(-1,0,0);
  71. C1 = rootJ.C1 * CFrame.new(-1,0,0);
  72. Factor = Vector3.new(-2/3,0,0);
  73. };
  74. [lhip] =
  75. {
  76. C0 = lhip.C0;
  77. C1 = lhip.C1;
  78. Factor = Vector3.new(0,0,2/3);
  79. };
  80. [rhip] =
  81. {
  82. C0 = rhip.C0;
  83. C1 = rhip.C1;
  84. Factor = Vector3.new(0,0,-2/3);
  85. };
  86. [rshoulder] =
  87. {
  88. C0 = rshoulder.C0;
  89. C1 = rshoulder.C1;
  90. Factor = Vector3.new(0,0,1/3);
  91. };
  92. [lshoulder] =
  93. {
  94. C0 = lshoulder.C0;
  95. C1 = lshoulder.C1;
  96. Factor = Vector3.new(0,0,-1/3);
  97. };
  98. [neck] =
  99. {
  100. C0 = neck.C0;
  101. C1 = neck.C1;
  102. Factor = Vector3.new(-2/3,0,0);
  103. };
  104. }
  105.  
  106. for _,state in pairs(offStates) do
  107. table.insert(connections,humanoid[state]:connect(function ()
  108. active = false
  109. end))
  110. end
  111.  
  112. for _,state in pairs(onStates) do
  113. table.insert(connections,humanoid[state]:connect(function (speed)
  114. active = (speed>1)
  115. end))
  116. end
  117.  
  118. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  119.  
  120. table.insert(connections,rs.RenderStepped:connect(function ()
  121. if active then
  122. if waveScale < 0.5 then
  123. waveScale = math.min(0.5,waveScale+scaleIncrement)
  124. end
  125. else
  126. if waveScale > 0 then
  127. waveScale = math.max(0,waveScale-scaleIncrement)
  128. end
  129. end
  130. local abs,cos = math.abs,math.cos
  131. local camY = c.CoordinateFrame.lookVector.Y
  132. updateY:FireServer(camY)
  133. for joint,def in pairs(RIG) do
  134. joint.C0 = def.C0 * CFrame.Angles(def.Factor.X*camY,def.Factor.Y*camY,def.Factor.Z*camY)
  135. joint.C1 = def.C1
  136. end
  137. rootJ.C0 = rootJ.C0 * CFrame.new(0,camY,0) -- Painful fix, but the player glides forward and backwards a bit when looking up and down without this.
  138. local headOffset = CFrame.new()
  139. if (c.Focus.p-c.CoordinateFrame.p).magnitude < 1 then
  140. c.FieldOfView = 90
  141. local dist = head.CFrame:toObjectSpace(torso.CFrame).p.magnitude
  142. headOffset = root.CFrame:toObjectSpace(head.CFrame) - Vector3.new(0,dist - ((1+camY)/8),0.25)
  143. else
  144. c.FieldOfView = 80
  145. end
  146. local t = cos(tick() * (math.pi*2.5))
  147. local bobble = CFrame.new((t/3)*waveScale,abs(t/5)*waveScale,0) -- Makes the view move side to side. The wave scale is tweened between 0 and 1 depending on if the player is walking or not.
  148. humanoid.CameraOffset = (headOffset * bobble).p
  149. end))
  150.  
  151. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  152.  
  153. function lock(part)
  154. if part and part:IsA("BasePart") then
  155. part.LocalTransparencyModifier = part.Transparency
  156. part.Changed:connect(function (property)
  157. part.LocalTransparencyModifier = part.Transparency
  158. end)
  159. end
  160. end
  161.  
  162. for _,v in pairs(char:GetChildren()) do
  163. lock(v)
  164. end
  165.  
  166. char.ChildAdded:connect(lock)
  167.  
  168. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  169.  
  170. humanoid.Died:connect(function ()
  171. for _,v in pairs(connections) do
  172. v:disconnect()
  173. end
  174. v.CameraOffset = Vector3.new()
  175. end)
  176.  
  177.  
  178.  
  179. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  180. end))
  181. RemoteEvent4.Name = "UpdateY"
  182. RemoteEvent4.Parent = Script2
  183. Script2.Name = "Put in Starter pack"
  184. Script2.Parent = mas
  185. table.insert(cors,sandbox(Script2,function()
  186.  
  187. updateY = script:WaitForChild("UpdateY")
  188.  
  189. function loadPlayerVariables(player)
  190. char = player.Character
  191. humanoid = char:WaitForChild("Humanoid")
  192. head = char:WaitForChild("Head")
  193. torso = char:WaitForChild("Torso")
  194. root = char:WaitForChild("HumanoidRootPart")
  195. rootJ = root:WaitForChild("RootJoint")
  196. lhip = torso:WaitForChild("Left Hip")
  197. lshoulder = torso:WaitForChild("Left Shoulder")
  198. rshoulder = torso:WaitForChild("Right Shoulder")
  199. rhip = torso:WaitForChild("Right Hip")
  200. neck = torso:WaitForChild("Neck")
  201. RIG = {
  202. [rootJ] =
  203. {
  204. C0 = rootJ.C0 * CFrame.new(-1,0,0);
  205. C1 = rootJ.C1 * CFrame.new(-1,0,0);
  206. Factor = Vector3.new(-2/3,0,0);
  207. };
  208. [lhip] =
  209. {
  210. C0 = lhip.C0;
  211. C1 = lhip.C1;
  212. Factor = Vector3.new(0,0,2/3);
  213. };
  214. [rhip] =
  215. {
  216. C0 = rhip.C0;
  217. C1 = rhip.C1;
  218. Factor = Vector3.new(0,0,-2/3);
  219. };
  220. [rshoulder] =
  221. {
  222. C0 = rshoulder.C0;
  223. C1 = rshoulder.C1;
  224. Factor = Vector3.new(0,0,1/3);
  225. };
  226. [lshoulder] =
  227. {
  228. C0 = lshoulder.C0;
  229. C1 = lshoulder.C1;
  230. Factor = Vector3.new(0,0,-1/3);
  231. };
  232. [neck] =
  233. {
  234. C0 = neck.C0;
  235. C1 = neck.C1;
  236. Factor = Vector3.new(-2/3,0,0);
  237. };
  238. }
  239. end
  240.  
  241. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  242.  
  243. updateY.OnServerEvent:connect(function (player,camY)
  244. if not char then
  245. loadPlayerVariables(player)
  246. end
  247. local abs,cos = math.abs,math.cos
  248. for joint,def in pairs(RIG) do
  249. joint.C0 = def.C0 * CFrame.Angles(def.Factor.X*camY,def.Factor.Y*camY,def.Factor.Z*camY)
  250. joint.C1 = def.C1
  251. end
  252. rootJ.C0 = rootJ.C0 * CFrame.new(0,camY,0)
  253. end)
  254.  
  255. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  256. end))
  257. LocalScript3.Name = "Client"
  258. LocalScript3.Parent = Script2
  259. table.insert(cors,sandbox(LocalScript3,function()
  260. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  261. wait(.2) -- Local Scripts can be really annoying sometimes.
  262.  
  263. player = game.Players.LocalPlayer
  264. c = workspace.CurrentCamera
  265. rs = game:GetService("RunService")
  266.  
  267. char = player.Character or player.CharacterAdded:wait()
  268.  
  269. while not char:IsDescendantOf(game) do
  270. wait(.75)
  271. end
  272.  
  273. humanoid = char:WaitForChild("Humanoid")
  274. head = char:WaitForChild("Head")
  275. torso = char:WaitForChild("Torso")
  276. root = char:WaitForChild("HumanoidRootPart")
  277. rootJ = root:WaitForChild("RootJoint")
  278. lhip = torso:WaitForChild("Left Hip")
  279. lshoulder = torso:WaitForChild("Left Shoulder")
  280. rshoulder = torso:WaitForChild("Right Shoulder")
  281. rhip = torso:WaitForChild("Right Hip")
  282. neck = torso:WaitForChild("Neck")
  283.  
  284. waveScale = 0
  285. scaleIncrement = 0.05
  286. lastY = 0
  287. pi2 = math.pi*2
  288.  
  289. offStates = {"Jumping","PlatformStanding","Ragdoll","Seated","FallingDown","FreeFalling","GettingUp","Swimming"}
  290. onStates = {"Running","Climbing"}
  291.  
  292. active = false
  293. rs = game:GetService("RunService")
  294. connections = {}
  295.  
  296. server = script.Parent
  297. updateY = server:WaitForChild("UpdateY")
  298.  
  299. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  300.  
  301. RIG = {
  302. [rootJ] =
  303. {
  304. C0 = rootJ.C0 * CFrame.new(-1,0,0);
  305. C1 = rootJ.C1 * CFrame.new(-1,0,0);
  306. Factor = Vector3.new(-2/3,0,0);
  307. };
  308. [lhip] =
  309. {
  310. C0 = lhip.C0;
  311. C1 = lhip.C1;
  312. Factor = Vector3.new(0,0,2/3);
  313. };
  314. [rhip] =
  315. {
  316. C0 = rhip.C0;
  317. C1 = rhip.C1;
  318. Factor = Vector3.new(0,0,-2/3);
  319. };
  320. [rshoulder] =
  321. {
  322. C0 = rshoulder.C0;
  323. C1 = rshoulder.C1;
  324. Factor = Vector3.new(0,0,1/3);
  325. };
  326. [lshoulder] =
  327. {
  328. C0 = lshoulder.C0;
  329. C1 = lshoulder.C1;
  330. Factor = Vector3.new(0,0,-1/3);
  331. };
  332. [neck] =
  333. {
  334. C0 = neck.C0;
  335. C1 = neck.C1;
  336. Factor = Vector3.new(-2/3,0,0);
  337. };
  338. }
  339.  
  340. for _,state in pairs(offStates) do
  341. table.insert(connections,humanoid[state]:connect(function ()
  342. active = false
  343. end))
  344. end
  345.  
  346. for _,state in pairs(onStates) do
  347. table.insert(connections,humanoid[state]:connect(function (speed)
  348. active = (speed>1)
  349. end))
  350. end
  351.  
  352. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  353.  
  354. table.insert(connections,rs.RenderStepped:connect(function ()
  355. if active then
  356. if waveScale < 0.5 then
  357. waveScale = math.min(0.5,waveScale+scaleIncrement)
  358. end
  359. else
  360. if waveScale > 0 then
  361. waveScale = math.max(0,waveScale-scaleIncrement)
  362. end
  363. end
  364. local abs,cos = math.abs,math.cos
  365. local camY = c.CoordinateFrame.lookVector.Y
  366. updateY:FireServer(camY)
  367. for joint,def in pairs(RIG) do
  368. joint.C0 = def.C0 * CFrame.Angles(def.Factor.X*camY,def.Factor.Y*camY,def.Factor.Z*camY)
  369. joint.C1 = def.C1
  370. end
  371. rootJ.C0 = rootJ.C0 * CFrame.new(0,camY,0) -- Painful fix, but the player glides forward and backwards a bit when looking up and down without this.
  372. local headOffset = CFrame.new()
  373. if (c.Focus.p-c.CoordinateFrame.p).magnitude < 1 then
  374. c.FieldOfView = 90
  375. local dist = head.CFrame:toObjectSpace(torso.CFrame).p.magnitude
  376. headOffset = root.CFrame:toObjectSpace(head.CFrame) - Vector3.new(0,dist - ((1+camY)/8),0.25)
  377. else
  378. c.FieldOfView = 80
  379. end
  380. local t = cos(tick() * (math.pi*2.5))
  381. local bobble = CFrame.new((t/3)*waveScale,abs(t/5)*waveScale,0) -- Makes the view move side to side. The wave scale is tweened between 0 and 1 depending on if the player is walking or not.
  382. humanoid.CameraOffset = (headOffset * bobble).p
  383. end))
  384.  
  385. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  386.  
  387. function lock(part)
  388. if part and part:IsA("BasePart") then
  389. part.LocalTransparencyModifier = part.Transparency
  390. part.Changed:connect(function (property)
  391. part.LocalTransparencyModifier = part.Transparency
  392. end)
  393. end
  394. end
  395.  
  396. for _,v in pairs(char:GetChildren()) do
  397. lock(v)
  398. end
  399.  
  400. char.ChildAdded:connect(lock)
  401.  
  402. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  403.  
  404. humanoid.Died:connect(function ()
  405. for _,v in pairs(connections) do
  406. v:disconnect()
  407. end
  408. v.CameraOffset = Vector3.new()
  409. end)
  410.  
  411.  
  412.  
  413. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  414. end))
  415. RemoteEvent4.Name = "UpdateY"
  416. RemoteEvent4.Parent = Script2
  417. for i,v in pairs(mas:GetChildren()) do
  418. v.Parent = script
  419. pcall(function() v:MakeJoints() end)
  420. end
  421. mas:Destroy()
  422. for i,v in pairs(cors) do
  423. spawn(function()
  424. pcall(v)
  425. end)
  426. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement