Advertisement
vacha

Old roblox animation

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