GemyScripter

old animations

Sep 7th, 2016
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. function waitForChild(parent, childName)
  2. local child = parent:findFirstChild(childName)
  3. if child then return child end
  4. while true do
  5. child = parent.ChildAdded:wait()
  6. if child.Name==childName then return child end
  7. end
  8. end
  9.  
  10. -- ANIMATION
  11.  
  12. -- declarations
  13.  
  14. local Figure = script.Parent
  15. local Torso = waitForChild(Figure, "Torso")
  16. local RightShoulder = waitForChild(Torso, "Right Shoulder")
  17. local LeftShoulder = waitForChild(Torso, "Left Shoulder")
  18. local RightHip = waitForChild(Torso, "Right Hip")
  19. local LeftHip = waitForChild(Torso, "Left Hip")
  20. local Neck = waitForChild(Torso, "Neck")
  21. local Humanoid = waitForChild(Figure, "Humanoid")
  22. local pose = "Standing"
  23.  
  24. local toolAnim = "None"
  25. local toolAnimTime = 0
  26.  
  27. -- functions
  28.  
  29. function onRunning(speed)
  30. if speed>0 then
  31. pose = "Running"
  32. else
  33. pose = "Standing"
  34. end
  35. end
  36.  
  37. function onDied()
  38. pose = "Dead"
  39. end
  40.  
  41. function onJumping()
  42. pose = "Jumping"
  43. end
  44.  
  45. function onClimbing()
  46. pose = "Climbing"
  47. end
  48.  
  49. function onGettingUp()
  50. pose = "GettingUp"
  51. end
  52.  
  53. function onFreeFall()
  54. pose = "FreeFall"
  55. end
  56.  
  57. function onFallingDown()
  58. pose = "FallingDown"
  59. end
  60.  
  61. function onSeated()
  62. pose = "Seated"
  63. end
  64.  
  65. function onPlatformStanding()
  66. pose = "PlatformStanding"
  67. end
  68.  
  69. function moveJump()
  70. RightShoulder.MaxVelocity = 0.5
  71. LeftShoulder.MaxVelocity = 0.5
  72. RightShoulder.DesiredAngle = 3.14
  73. LeftShoulder.DesiredAngle = -3.14
  74. RightHip.DesiredAngle = 0
  75. LeftHip.DesiredAngle = 0
  76. end
  77.  
  78.  
  79. -- same as jump for now
  80.  
  81. function moveFreeFall()
  82. RightShoulder.MaxVelocity = 0.5
  83. LeftShoulder.MaxVelocity = 0.5
  84. RightShoulder.DesiredAngle = 3.14
  85. LeftShoulder.DesiredAngle = -3.14
  86. RightHip.DesiredAngle = 0
  87. LeftHip.DesiredAngle = 0
  88. end
  89.  
  90. function moveSit()
  91. RightShoulder.MaxVelocity = 0.15
  92. LeftShoulder.MaxVelocity = 0.15
  93. RightShoulder.DesiredAngle = 3.14 /2
  94. LeftShoulder.DesiredAngle = -3.14 /2
  95. RightHip.DesiredAngle = 3.14 /2
  96. LeftHip.DesiredAngle = -3.14 /2
  97. end
  98.  
  99. function getTool()
  100. for _, kid in ipairs(Figure:GetChildren()) do
  101. if kid.className == "Tool" then return kid end
  102. end
  103. return nil
  104. end
  105.  
  106. function getToolAnim(tool)
  107. for _, c in ipairs(tool:GetChildren()) do
  108. if c.Name == "toolanim" and c.className == "StringValue" then
  109. return c
  110. end
  111. end
  112. return nil
  113. end
  114.  
  115. function animateTool()
  116.  
  117. if (toolAnim == "None") then
  118. RightShoulder.DesiredAngle = 1.57
  119. return
  120. end
  121.  
  122. if (toolAnim == "Slash") then
  123. RightShoulder.MaxVelocity = 0.5
  124. RightShoulder.DesiredAngle = 0
  125. return
  126. end
  127.  
  128. if (toolAnim == "Lunge") then
  129. RightShoulder.MaxVelocity = 0.5
  130. LeftShoulder.MaxVelocity = 0.5
  131. RightHip.MaxVelocity = 0.5
  132. LeftHip.MaxVelocity = 0.5
  133. RightShoulder.DesiredAngle = 1.57
  134. LeftShoulder.DesiredAngle = 1.0
  135. RightHip.DesiredAngle = 1.57
  136. LeftHip.DesiredAngle = 1.0
  137. return
  138. end
  139. end
  140.  
  141. function move(time)
  142. local amplitude
  143. local frequency
  144.  
  145. if (pose == "Jumping") then
  146. moveJump()
  147. return
  148. end
  149.  
  150. if (pose == "FreeFall") then
  151. moveFreeFall()
  152. return
  153. end
  154.  
  155. if (pose == "Seated") then
  156. moveSit()
  157. return
  158. end
  159.  
  160. local climbFudge = 0
  161.  
  162. if (pose == "Running") then
  163. RightShoulder.MaxVelocity = 0.15
  164. LeftShoulder.MaxVelocity = 0.15
  165. amplitude = 1
  166. frequency = 9
  167. elseif (pose == "Climbing") then
  168. RightShoulder.MaxVelocity = 0.5
  169. LeftShoulder.MaxVelocity = 0.5
  170. amplitude = 1
  171. frequency = 9
  172. climbFudge = 3.14
  173. else
  174. amplitude = 0.1
  175. frequency = 1
  176. end
  177.  
  178. desiredAngle = amplitude * math.sin(time*frequency)
  179.  
  180. RightShoulder.DesiredAngle = desiredAngle + climbFudge
  181. LeftShoulder.DesiredAngle = desiredAngle - climbFudge
  182. RightHip.DesiredAngle = -desiredAngle
  183. LeftHip.DesiredAngle = -desiredAngle
  184.  
  185.  
  186. local tool = getTool()
  187.  
  188. if tool then
  189.  
  190. animStringValueObject = getToolAnim(tool)
  191.  
  192. if animStringValueObject then
  193. toolAnim = animStringValueObject.Value
  194. -- message recieved, delete StringValue
  195. animStringValueObject.Parent = nil
  196. toolAnimTime = time + .3
  197. end
  198.  
  199. if time > toolAnimTime then
  200. toolAnimTime = 0
  201. toolAnim = "None"
  202. end
  203.  
  204. animateTool()
  205.  
  206.  
  207. else
  208. toolAnim = "None"
  209. toolAnimTime = 0
  210. end
  211. end
  212.  
  213.  
  214. -- connect events
  215.  
  216. Humanoid.Died:connect(onDied)
  217. Humanoid.Running:connect(onRunning)
  218. Humanoid.Jumping:connect(onJumping)
  219. Humanoid.Climbing:connect(onClimbing)
  220. Humanoid.GettingUp:connect(onGettingUp)
  221. Humanoid.FreeFalling:connect(onFreeFall)
  222. Humanoid.FallingDown:connect(onFallingDown)
  223. Humanoid.Seated:connect(onSeated)
  224. Humanoid.PlatformStanding:connect(onPlatformStanding)
  225.  
  226. -- main program
  227.  
  228. local runService = game:service("RunService");
  229.  
  230. while Figure.Parent~=nil do
  231. local _, time = wait(0.1)
  232. move(time)
  233. end
Add Comment
Please, Sign In to add comment