Advertisement
StefanBashkir

ROBLOX Pre-2013 Animate Script

Dec 22nd, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.00 KB | None | 0 0
  1. local cachecopy = script.Parent:Clone()
  2. local npc = script.Parent
  3. local leftarm = npc["Left Arm"]
  4. local leftleg = npc["Left Leg"]
  5. local rightarm = npc["Right Arm"]
  6. local rightleg = npc["Right Leg"]
  7. local torso = npc["Torso"]
  8. local head = npc["Head"]
  9. local joints = {}
  10. local canRespawn = true
  11. local stance = "idle"
  12.  
  13. function MakeHuman()
  14.     local h = Instance.new("Humanoid")
  15.     h.MaxHealth = 100
  16.     h.Health = 100
  17.     h.WalkSpeed = 16
  18.     h.Parent = npc
  19. end
  20.  
  21. function ConnectWithInstance(instance)
  22.  
  23.     local c = Instance.new(instance)
  24.     c.Part0 = torso
  25.     c.Part1 = head
  26.     c.C1 = c.Part1.CFrame:toObjectSpace(c.Part0.CFrame)
  27.     c.Name = "HeadConnector"
  28.     joints[c.Name] = c
  29.     c.Parent = game.JointsService
  30.     c = nil
  31.  
  32.     local c = Instance.new(instance)
  33.     c.Part0 = torso
  34.     c.Part1 = leftarm
  35.     c.C0 = CFrame.new(-1.5,.5,0) * CFrame.Angles(math.rad(90),math.rad(90),math.rad(90))
  36.     c.C1 = CFrame.new(0,-.5,0)
  37.     c.Name = "LeftArmConnector"
  38.     c.MaxVelocity = .15
  39.     joints[c.Name] = c
  40.     c.Parent = game.JointsService
  41.     c = nil
  42.  
  43.     local c = Instance.new(instance)
  44.     c.Part0 = torso
  45.     c.Part1 = leftleg
  46.     c.C0 = CFrame.new(-.5,-1.5,0) * CFrame.Angles(math.rad(90),math.rad(90),math.rad(90))
  47.     c.C1 = CFrame.new(0,-.5,0)
  48.     c.Name = "LeftLegConnector"
  49.     c.MaxVelocity = .15
  50.     joints[c.Name] = c
  51.     c.Parent = game.JointsService
  52.     c = nil
  53.  
  54.     local c = Instance.new(instance)
  55.     c.Part0 = torso
  56.     c.Part1 = rightarm
  57.     c.C0 = CFrame.new(1.5,.5,0) * CFrame.Angles(math.rad(90),math.rad(90),math.rad(90))
  58.     c.C1 = CFrame.new(0,-.5,0)
  59.     c.Name = "RightArmConnector"
  60.     c.MaxVelocity = .15
  61.     joints[c.Name] = c
  62.     c.Parent = game.JointsService
  63.     c = nil
  64.  
  65.     local c = Instance.new(instance)
  66.     c.Part0 = torso
  67.     c.Part1 = rightleg
  68.     c.C0 = CFrame.new(.5,-1.5,0) * CFrame.Angles(math.rad(90),math.rad(90),math.rad(90))
  69.     c.C1 = CFrame.new(0,-.5,0)
  70.     c.Name = "RightLegConnector"
  71.     c.MaxVelocity = .15
  72.     joints[c.Name] = c
  73.     c.Parent = game.JointsService
  74.     c = nil
  75.  
  76. end
  77.  
  78. function UnAnchor()
  79.     for i,v in pairs(script.Parent:GetChildren()) do
  80.         if v:IsA("BasePart") then
  81.             v.Anchored = false
  82.         end
  83.     end
  84. end
  85.  
  86. function AnimateFrame(time)
  87.     local a
  88.     local f
  89.     local ca = 0
  90.     if stance == "idle" then
  91.         joints["RightArmConnector"].MaxVelocity = .15
  92.         joints["LeftArmConnector"].MaxVelocity = .15
  93.         a = .1
  94.         f = 1
  95.     elseif stance == "running" then
  96.         joints["RightArmConnector"].MaxVelocity = .15
  97.         joints["LeftArmConnector"].MaxVelocity = .15
  98.         a = 1
  99.         f = 9
  100.     elseif stance == "jumping" then
  101.         joints["RightArmConnector"].MaxVelocity = .5
  102.         joints["LeftArmConnector"].MaxVelocity = .5
  103.         joints["RightArmConnector"].DesiredAngle = 3.14
  104.         joints["LeftArmConnector"].DesiredAngle = 3.14
  105.         joints["RightLegConnector"].DesiredAngle = 0
  106.         joints["LeftLegConnector"].DesiredAngle = 0
  107.         return
  108.     elseif stance == "climbing" then
  109.         joints["RightArmConnector"].MaxVelocity = .5
  110.         joints["LeftArmConnector"].MaxVelocity = .5
  111.         a = 1
  112.         f = 9
  113.         ca = 3.14
  114.     elseif stance == "sitting" then
  115.         joints["RightArmConnector"].MaxVelocity = .15
  116.         joints["LeftArmConnector"].MaxVelocity = .15
  117.         joints["RightArmConnector"].DesiredAngle = 0
  118.         joints["LeftArmConnector"].DesiredAngle = 0
  119.         joints["RightLegConnector"].DesiredAngle = 1.57
  120.         joints["LeftLegConnector"].DesiredAngle = 1.57
  121.         return
  122.     end
  123.     local da = a * math.sin(time*f)
  124.     joints["RightArmConnector"].DesiredAngle = -da - ca
  125.     joints["LeftArmConnector"].DesiredAngle = da + ca
  126.     joints["RightLegConnector"].DesiredAngle = da
  127.     joints["LeftLegConnector"].DesiredAngle = -da
  128. end
  129.  
  130. ConnectWithInstance("Motor6D")
  131. MakeHuman()
  132. UnAnchor()
  133.  
  134. npc.Humanoid.Running:connect(function(speed)
  135.     if speed > 0 then
  136.         stance = "running"
  137.     else
  138.         stance = "idle"
  139.     end
  140. end)
  141.  
  142. npc.Humanoid.Jumping:connect(function()
  143.     stance = "jumping"
  144. end)
  145.  
  146. npc.Humanoid.FreeFalling:connect(function()
  147.     stance = "jumping" -- On purpose!
  148. end)
  149.  
  150. npc.Humanoid.Seated:connect(function()
  151.     stance = "sitting"
  152. end)
  153.  
  154. coroutine.wrap(function()
  155.     while true do
  156.         local gt,time = wait()
  157.         AnimateFrame(time)
  158.     end
  159. end)()
  160.  
  161.  
  162.  
  163.  
  164. -- Custom Code Below
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement