Prephy

classic animation

Apr 11th, 2021 (edited)
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.76 KB | None | 0 0
  1. --suitable for void script builder, made by Protofer_S, and yes i changed my username
  2.  
  3.     NLS([[
  4.  
  5. part = Instance.new("Part",game.Lighting)
  6. part.Anchored = true
  7. equiped=false
  8. part.FormFactor = Enum.FormFactor.Custom
  9. part.CanCollide = false
  10. part.LeftSurface = Enum.SurfaceType.SmoothNoOutlines
  11. part.TopSurface = Enum.SurfaceType.SmoothNoOutlines
  12. part.RightSurface = Enum.SurfaceType.SmoothNoOutlines
  13. part.FrontSurface = Enum.SurfaceType.SmoothNoOutlines
  14. part.BottomSurface = Enum.SurfaceType.SmoothNoOutlines
  15. part.Size = Vector3.new(2,0.2,2)
  16. part.BackSurface = Enum.SurfaceType.SmoothNoOutlines
  17. part.BrickColor = BrickColor.new("Lime green")
  18. mesh = Instance.new("CylinderMesh",part)
  19. mesh.Scale = Vector3.new(1, 0.100000001, 1)
  20. mouse=game:service'Players'.LocalPlayer:GetMouse()
  21. ClearAngles=function(cf)
  22. return CFrame.new(cf.x,cf.y,cf.z)
  23. end
  24. game:service'RunService'.RenderStepped:connect(function()
  25. if mouse.Hit~=nil and mouse.Target~=nil and mouse.Target~=part then
  26. part.CFrame=ClearAngles(mouse.Hit)
  27. part.Transparency=0
  28. elseif mouse.Target==nil then
  29. part.Transparency=1
  30. end
  31. local th=0
  32. for i,v in pairs(game:service'Players'.LocalPlayer.Character:children()) do
  33. if v:IsA'Tool' then
  34. th=th+1
  35. end
  36. end
  37. for i,v in pairs(game:service'Players'.LocalPlayer.Backpack:children()) do
  38. if v:IsA'HopperBin' and v.Active==true then
  39. th=th+1
  40. end
  41. end
  42. if th~= 0 then
  43. part.Transparency=1
  44. equiped=true
  45. else
  46. equiped=false
  47. end
  48. end)
  49. mouse.Button1Down:connect(function()
  50. coroutine.resume(coroutine.create(function()
  51. for i,v in pairs(game:service'Players'.LocalPlayer.Character:children()) do
  52. if v:IsA'Humanoid' and equiped==false then
  53. v:MoveTo(part.Position)
  54. end
  55. end
  56. end))
  57. end)
  58.  
  59.  
  60. ]],owner.Backpack)
  61.  
  62.  
  63.  
  64.     function waitForChild(parent, childName)
  65.         local child = parent:findFirstChild(childName)
  66.         if child then return child end
  67.         while true do
  68.             child = parent.ChildAdded:wait()
  69.             if child.Name==childName then return child end
  70.         end
  71.     end
  72.  
  73.  
  74. local Figure = owner.Character
  75. local an = waitForChild(Figure,"Animate")
  76. an.Disabled=true
  77. local Torso = waitForChild(Figure,"Torso")
  78. local Humanoid = waitForChild(Figure, "Humanoid")
  79. Humanoid.BreakJointsOnDeath=false
  80. Humanoid:ClearAllChildren()
  81. local Humanoidroot = waitForChild(Figure,"HumanoidRootPart")
  82. Instance.new("Animator",Humanoid).Name="Animator"
  83.  
  84.  
  85. for i,g in pairs(Humanoidroot:GetDescendants()) do
  86.     if g:IsA("Sound") then
  87.         g:Destroy()
  88.         end
  89.     end
  90.  
  91.  
  92.  
  93. function makeJoint(limbName, jointName, c0, c1)
  94.     local limb = waitForChild(Figure, limbName)
  95.     if limb.Name=="Head" then
  96.        
  97.     else
  98.         limb:BreakJoints() 
  99.  
  100.     end
  101.         local joint = Instance.new"Motor6D"
  102.        joint.Name = jointName
  103.        
  104.         joint.Part0 = Torso
  105.         joint.Part1 = limb
  106.         joint.C0 = c0
  107.         joint.C1 = c1
  108.         joint.MaxVelocity = 0.5
  109.         joint.archivable = true
  110.         joint.Parent = Torso
  111.         return joint
  112.     end
  113.  
  114.  
  115.  
  116.     local Neck = makeJoint("Head","Neck", CFrame.new(0, 1, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0), CFrame.new(0, -0.5, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0))
  117.     local RightShoulder = makeJoint("Right Arm", "Right Shoulder", CFrame.new(1, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0), CFrame.new(-0.5, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0))
  118.     local LeftShoulder = makeJoint("Left Arm", "Left Shoulder", CFrame.new(-1, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0), CFrame.new(0.5, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0))
  119.     local RightHip = makeJoint("Right Leg", "Right Hip", CFrame.new(1, -1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0), CFrame.new(0.5, 1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0))
  120.     local LeftHip = makeJoint("Left Leg", "Left Hip", CFrame.new(-1, -1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0), CFrame.new(-0.5, 1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0))
  121.  
  122.  
  123.  
  124.  
  125. Humanoid.BreakJointsOnDeath=true
  126.  
  127.  
  128. -- util
  129.    
  130.     function sound()
  131.    
  132. function waitForChild(parent, childName)
  133.     while true do
  134.         local child = parent:findFirstChild(childName)
  135.         if child then
  136.             return child
  137.         end
  138.         parent.ChildAdded:wait()
  139.     end
  140. end
  141.  
  142. function newSound(id)
  143.     local sound = Instance.new("Sound")
  144.     sound.SoundId = id
  145.     sound.Parent = owner.Character.Head
  146.     sound.Volume=1
  147.     return sound
  148. end
  149.  
  150. -- declarations
  151. --rbxasset://sounds/button.wav
  152. local sDied = newSound("rbxasset://sounds/uuhhh.wav")
  153. local sFallingDown = newSound("rbxasset://sounds/splat.wav")
  154. local sFreeFalling = newSound("rbxassetid://2428506580")
  155. local sGettingUp = newSound("rbxasset://sounds/hit.wav")
  156. local sJumping = newSound("rbxasset://sounds/button.wav")
  157. local sRunning = newSound("rbxasset://sounds/bfsl-minifigfoots1.mp3")
  158. sRunning.Looped = true
  159.  
  160.  
  161.  
  162. -- functions
  163.  
  164. function onDied()
  165.     sDied:play()
  166. end
  167.  
  168. function onState(state, sound)
  169.     if state then
  170.         sound:play()
  171.     else
  172.         sound:pause()
  173.     end
  174. end
  175.  
  176. function onRunning(speed)
  177.     if speed>0 then
  178.         sRunning:play()
  179.     else
  180.         sRunning:pause()
  181.     end
  182. end
  183.  
  184. -- connect up
  185.  
  186. Humanoid.Died:connect(onDied)
  187. Humanoid.Running:connect(onRunning)
  188. Humanoid.Jumping:connect(function(state) onState(state, sJumping) end)
  189. Humanoid.GettingUp:connect(function(state) onState(state, sGettingUp) end)
  190. Humanoid.FreeFalling:connect(function(state) onState(state, sFreeFalling) end)
  191. Humanoid.FallingDown:connect(function(state) onState(state, sFallingDown) end)
  192.  
  193.  
  194. end
  195.  
  196.  
  197.  
  198.  
  199. function waitForChild(parent, childName)
  200.     while true do
  201.         local child = parent:findFirstChild(childName)
  202.         if child then
  203.             return child
  204.         end
  205.         parent.ChildAdded:wait()
  206.     end
  207. end
  208.  
  209. -- declarations
  210.  
  211. --local Figure = owner.Character
  212. --local Torso = waitForChild(Figure, "Torso")
  213. --local Humanoid = waitForChild(Figure, "Humanoid")
  214. --local RightShoulder = waitForChild(Torso, "Right Shoulder")
  215. --local LeftShoulder = waitForChild(Torso, "Left Shoulder")
  216. --local RightHip = waitForChild(Torso, "Right Hip")
  217. --local LeftHip = waitForChild(Torso, "Left Hip")
  218. --local Neck = waitForChild(Torso, "Neck")
  219.  
  220.  
  221. -- functions
  222.  
  223.  
  224.  
  225. local toolAnim = "None"
  226. local toolAnimTime = 0
  227.  
  228. -- functions
  229.  
  230. function onRunning(speed)
  231.     if speed>0 then
  232.         pose = "Running"
  233.     else
  234.         pose = "Standing"
  235.     end
  236. end
  237.  
  238. function onDied()
  239.     pose = "Dead"
  240. end
  241.  
  242. function onJumping(state)
  243.     pose = "Jumping"
  244. end
  245.  
  246. function onClimbing()
  247.     pose = "Climbing"
  248. end
  249.  
  250. function onGettingUp(state)
  251.     pose = "GettingUp"
  252. end
  253.  
  254. function onFreeFall(state)
  255.     pose = "FreeFall"
  256. end
  257.  
  258. function onFallingDown(state)
  259.     pose = "FallingDown"
  260. end
  261.  
  262. function onSeated()
  263.     pose = "Seated"
  264. end
  265.  
  266. function moveJump()
  267.     RightShoulder.MaxVelocity = 0.5
  268.     LeftShoulder.MaxVelocity = 0.5
  269.     RightShoulder.DesiredAngle = 3.14
  270.     LeftShoulder.DesiredAngle = -3.14
  271.     RightHip.DesiredAngle = 0
  272.     LeftHip.DesiredAngle = 0
  273. end
  274.  
  275.  
  276. -- same as jump for now
  277.  
  278. function moveFreeFall()
  279.     RightShoulder.MaxVelocity = 0.5
  280.     LeftShoulder.MaxVelocity = 0.5
  281.     RightShoulder.DesiredAngle = 3.14
  282.     LeftShoulder.DesiredAngle = -3.14
  283.     RightHip.DesiredAngle = 0
  284.     LeftHip.DesiredAngle = 0
  285. end
  286.  
  287. function moveSit()
  288.     RightShoulder.MaxVelocity = 0.15
  289.     LeftShoulder.MaxVelocity = 0.15
  290.     RightShoulder.DesiredAngle = 3.14 /2
  291.     LeftShoulder.DesiredAngle = -3.14 /2
  292.     RightHip.DesiredAngle = 3.14 /2
  293.     LeftHip.DesiredAngle = -3.14 /2
  294. end
  295.  
  296. local function getTool()
  297.     for i, v in ipairs(Figure:GetChildren()) do
  298.         if v:IsA"Tool" then
  299.             return v
  300.         end
  301.     end
  302.     return nil
  303. end
  304.  
  305. function getToolAnim(tool)
  306.     for _, c in ipairs(tool:GetChildren()) do
  307.         if c.Name == "toolanim" and c.className == "StringValue" then
  308.             return c
  309.         end
  310.     end
  311.     return nil
  312. end
  313.  
  314. function animateTool()
  315.  
  316.     if (toolAnim == "None") then
  317.         RightShoulder.DesiredAngle = 1.57
  318.         return
  319.     end
  320.  
  321.     if (toolAnim == "Slash") then
  322.         RightShoulder.MaxVelocity = 0.5
  323.         RightShoulder.DesiredAngle = 0
  324.         return
  325.     end
  326.  
  327.     if (toolAnim == "Lunge") then
  328.         RightShoulder.MaxVelocity = 0.5
  329.         LeftShoulder.MaxVelocity = 0.5
  330.         RightHip.MaxVelocity = 0.5
  331.         LeftHip.MaxVelocity = 0.5
  332.         RightShoulder.DesiredAngle = 1.57
  333.         LeftShoulder.DesiredAngle = 1.0
  334.         RightHip.DesiredAngle = 1.57
  335.         LeftHip.DesiredAngle = 1.0
  336.         return
  337.     end
  338. end
  339.  
  340. function move(time)
  341.     local amplitude
  342.     local frequency
  343.  
  344.     if (pose == "Jumping") then
  345.         moveJump()
  346.         return
  347.     end
  348.  
  349.     if (pose == "FreeFall") then
  350.         moveFreeFall()
  351.         return
  352.     end
  353.  
  354.     if (pose == "Seated") then
  355.         moveSit()
  356.         return
  357.     end
  358.  
  359.     local climbFudge = 0
  360.  
  361.     if (pose == "Running") then
  362.         RightShoulder.MaxVelocity = 0.15
  363.         LeftShoulder.MaxVelocity = 0.15
  364.         amplitude = .99
  365.         frequency = 9
  366.     elseif (pose == "Climbing") then
  367.         RightShoulder.MaxVelocity = 0.5
  368.         LeftShoulder.MaxVelocity = 0.5
  369.         amplitude = .99
  370.         frequency = 9
  371.         climbFudge = 3.14
  372.     else
  373.         amplitude = 0.1
  374.         frequency = 1
  375.     end
  376.  
  377.     desiredAngle = amplitude * math.sin(time*frequency)
  378.  
  379.     RightShoulder.DesiredAngle = desiredAngle + climbFudge
  380.     LeftShoulder.DesiredAngle = desiredAngle - climbFudge
  381.     RightHip.DesiredAngle = -desiredAngle
  382.     LeftHip.DesiredAngle = -desiredAngle
  383.  
  384.  
  385.     local tool = getTool()
  386.  
  387.     if tool then
  388.  
  389.         animStringValueObject = getToolAnim(tool)
  390.  
  391.         if animStringValueObject then
  392.             toolAnim = animStringValueObject.Value
  393.             -- message recieved, delete StringValue
  394.             animStringValueObject.Parent = nil
  395.             toolAnimTime = time + .3
  396.         end
  397.  
  398.         if time > toolAnimTime then
  399.             toolAnimTime = 0
  400.             toolAnim = "None"
  401.         end
  402.  
  403.         animateTool()
  404.  
  405.  
  406.     else
  407.         toolAnim = "None"
  408.         toolAnimTime = 0
  409.     end
  410. end
  411.  
  412.  
  413. -- connect events
  414.  
  415. Humanoid.Died:connect(onDied)
  416. Humanoid.Running:connect(onRunning)
  417. Humanoid.Jumping:connect(onJumping)
  418. Humanoid.Climbing:connect(onClimbing)
  419. Humanoid.GettingUp:connect(onGettingUp)
  420. Humanoid.FreeFalling:connect(onFreeFall)
  421. Humanoid.FallingDown:connect(onFallingDown)
  422. Humanoid.Seated:connect(onSeated)
  423.  
  424.  
  425.     sound()
  426.  
  427. -- main program
  428.  
  429. --local runService = game:service("RunService");
  430.  
  431. game:GetService('RunService').Heartbeat:Connect(function()
  432. if Figure.Parent~=nil then
  433. local _, time = wait()
  434.     move(time)
  435. end
  436.  
  437. end)
  438.  
  439. --while Figure.Parent~=nil do
  440.     --local _, time = wait(0.1)
  441.     --move(time)
  442. --end
  443.  
  444.    
  445.    
  446.  
  447.  
  448.  
  449.    
  450.    
Add Comment
Please, Sign In to add comment