Advertisement
StefanBashkir

ROBLOX Animation Script (Pre 2013) Full

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