Advertisement
jordan83221

Nunchuck

Mar 26th, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.22 KB | None | 0 0
  1. local next=next
  2. local gravity=0.09
  3. local friction=0.9
  4. local bounce=0.8
  5. local drag=Instance.new("Part",workspace)
  6. drag.Name="Dragger"
  7. drag.Anchored=true
  8. drag.CanCollide=false
  9. drag.Locked=true
  10. deselected=true
  11. drag.Transparency=1
  12. drag.Position=Vector3.new(0,50,0)
  13. local player=game.Players.LocalPlayer
  14. local char=player.Character
  15. local torso=player.Character.Torso
  16. local humanoid=player.Character.Humanoid
  17. local head=player.Character.Head
  18. local camera=workspace.CurrentCamera
  19. local RA=char["Right Arm"]
  20. local LA=char["Left Arm"]
  21. local RL=char["Right Leg"]
  22. local LL=char["Left Leg"]
  23. local RS=char.Torso["Right Shoulder"]
  24. local LS=char.Torso["Left Shoulder"]
  25. local T=char.Torso
  26. local mouse=player:GetMouse()
  27. local speed=100
  28. local slashing=false
  29. local spinning=false
  30. local swiping=false
  31. local function dist(p0,p1)
  32.     local dx=p1.CFrame.x-p0.CFrame.x
  33.     local dy=p1.CFrame.y-p0.CFrame.y
  34.     local dz=p1.CFrame.z-p0.CFrame.z
  35.     return math.sqrt(dx*dx+dy*dy+dz*dz)
  36. end
  37. local points={}
  38. local joints={}
  39. local handle=Instance.new("Part",player.Character)
  40. handle.Name="Handle"
  41. handle.Size=Vector3.new(.5,3,.5)
  42. handle.Transparency=0
  43. handle.Anchored=true
  44. handle.CanCollide=false
  45. handle.BrickColor=BrickColor.new("New Yeller")
  46. local cymesh=Instance.new("CylinderMesh",handle)
  47. cymesh.Scale=Vector3.new(0.5,1,0.5)
  48. local function createPoint(x,y,z,pinned)
  49.     local t = {x=x,y=y,z=z,oldx=x-0.4,oldy=y-0.4,oldz=z-0.4,pinned=pinned}
  50.     points[#points+1]=t
  51.     return t
  52. end
  53. local function createJoint(point1,point2,distance,line)
  54.     local t = {point1=point1,point2=point2,distance=distance,line=line}
  55.     table.insert(joints,t)
  56. end
  57. local function drawLine()
  58.     for i=1,#joints do
  59.         local j=joints[i]
  60.         local line=j.line
  61.         if not line then
  62.             line=Instance.new("Part",player.Character)
  63.             line.Name=tostring(i)
  64.             line.Anchored=true
  65.             line.CanCollide=false
  66.             line.BottomSurface="Smooth"
  67.             line.TopSurface="Smooth"
  68.             j.line=line
  69.             if line.Name~=tostring(#joints) then
  70.                 local mesh=Instance.new("SpecialMesh",line)
  71.                 mesh.Name="Mesh"
  72.                 mesh.MeshId="http://www.roblox.com/asset/?id=3270017"
  73.                 mesh.Scale=Vector3.new(0.4,0.6,0.6)
  74.             else
  75.                 local mesh=Instance.new("CylinderMesh",line)
  76.                 mesh.Scale=Vector3.new(1,3,1)
  77.                 coroutine.resume(coroutine.create(function()
  78.                     line.Touched:connect(function(hit)
  79.                         pcall(function()
  80.                             if hit.Parent.Parent:IsA("Model") then
  81.                                 local playerHit=game.Players:GetPlayerFromCharacter(hit.Parent.Parent)
  82.                                 if playerHit then
  83.                                     if playerHit.Name~="Voreli" then
  84.                                         if playerHit.Character:FindFirstChild("Humanoid") then
  85.                                             playerHit.Character.Humanoid.Health=playerHit.Character.Humanoid.Health-5
  86.                                         end
  87.                                     end
  88.                                 end
  89.                             end
  90.                         end)
  91.                     end)
  92.                 end))
  93.             end
  94.         end
  95.         local dx=j.point2.x-j.point1.x
  96.         local dy=j.point2.y-j.point1.y
  97.         local dz=j.point2.z-j.point1.z
  98.         line.BrickColor=BrickColor.new("Really Blue")
  99.         line.Size=Vector3.new(1,1,1)
  100.         local distance=math.sqrt(dx*dx+dy*dy+dz*dz)
  101.         if line.Name~=tostring(#joints) then
  102.             line.BrickColor=BrickColor.new("Really blue")
  103.             line.Size=Vector3.new(1,1,1)
  104.         else
  105.             line.BrickColor=BrickColor.new("New Yeller")
  106.             line.Size=Vector3.new(0.2,1,0.2)
  107.         end
  108.         if line.Name~=tostring(#joints) then
  109.             if tonumber(line.Name)%2==0 then
  110.                 line.CFrame=CFrame.new(Vector3.new(j.point1.x,j.point1.y,j.point1.z),Vector3.new(j.point2.x,j.point2.y,j.point2.z))*CFrame.Angles(math.rad(100),0,0)
  111.                 *CFrame.new(0,0,-distance/2)
  112.                 line.CFrame=line.CFrame*CFrame.Angles(0,math.rad(100),0)
  113.             else
  114.                 line.CFrame=CFrame.new(Vector3.new(j.point1.x,j.point1.y,j.point1.z),Vector3.new(j.point2.x,j.point2.y,j.point2.z))*CFrame.Angles(math.rad(100),0,0)
  115.                 *CFrame.new(0,0,-distance/2)
  116.             end
  117.         else
  118.             line.CFrame=CFrame.new(Vector3.new(j.point1.x,j.point1.y,j.point1.z),Vector3.new(j.point2.x,j.point2.y,j.point2.z))*CFrame.Angles(math.rad(100),0,0)
  119.             *CFrame.new(0,-1.2,-distance/2)
  120.         end
  121.     end
  122. end
  123. local width=1
  124. local height=5
  125. local l=0.45
  126. for y=1,height do
  127.     for x=1,width do
  128.         createPoint(l*x,25-l*y,0,y==1)
  129.         if x>1 then
  130.             createJoint(points[width*(y-1)+x-1],points[width*(y-1)+x],l)
  131.         end
  132.         if y>1 then
  133.             createJoint(points[width*(y-2)+x],points[width*(y-1)+x],l)
  134.         end
  135.     end
  136. end
  137. --[[local rlad=dist(RA,LA)
  138. local rlld=dist(RL,LL)
  139. local rlald=dist(RA,LL)
  140. local rllad=dist(LA,RL)
  141. local rrla=dist(RA,RL)
  142. local llla=dist(LL,LA)
  143. local rat=dist(RA,torso)
  144. local lat=dist(LA,torso)
  145. local rlt=dist(RL,torso)
  146. local llt=dist(LL,torso)
  147. local ra1=createPoint(RA.CFrame.X,RA.CFrame.Y,RA.CFrame.Z,false)
  148. local la1=createPoint(LA.CFrame.X,LA.CFrame.Y,LA.CFrame.Z,false)
  149. local rl1=createPoint(RL.CFrame.X,RL.CFrame.Y,RL.CFrame.Z,false)
  150. local ll1=createPoint(LL.CFrame.X,LL.CFrame.Y,LL.CFrame.Z,false)
  151. local tt=createPoint(torso.CFrame.X,torso.CFrame.Y,torso.CFrame.Z,false)
  152. createJoint(ra1,la1,rlad)
  153. createJoint(rl1,ll1,rlld)
  154. createJoint(tt,ra1,rat)
  155. createJoint(tt,la1,lat)
  156. createJoint(]]
  157. local function updatePoints()
  158.     for i=1,#points do
  159.         local p=points[i]
  160.         if not p.pinned then
  161.             local vx=(p.x-p.oldx)*friction;
  162.             local vy=-((p.y-p.oldy)*friction);
  163.             local vz=(p.z-p.oldz)*friction;
  164.             p.oldx=p.x
  165.             p.oldy=p.y
  166.             p.oldz=p.z
  167.             p.x=p.x+vx
  168.             p.y=p.y-vy
  169.             p.z=p.z+vz
  170.             p.y=p.y-gravity
  171.             if p.y<0 then
  172.                 p.y=0
  173.             end
  174.         end
  175.     end
  176. end
  177. local function updateSticks()
  178.     for i=1,#joints do
  179.         local j=joints[i]
  180.         local dx=j.point2.x-j.point1.x
  181.         local dy=j.point2.y-j.point1.y
  182.         local dz=j.point2.z-j.point1.z
  183.         local distance=math.sqrt(dx*dx+dy*dy+dz*dz)
  184.         local difference=j.distance-distance
  185.         local percent=difference/distance/2
  186.         local offsetX=dx*percent;
  187.         local offsetY=dy*percent;
  188.         local offsetZ=dz*percent;
  189.         if j.point1.pinned or j.point2.pinned then
  190.             offsetX=offsetX*2
  191.             offsetY=offsetY*2
  192.             offsetZ=offsetZ*2
  193.         end
  194.         if not j.point1.pinned then
  195.             j.point1.x=j.point1.x-offsetX
  196.             j.point1.y=j.point1.y-offsetY
  197.             j.point1.z=j.point1.z-offsetZ
  198.         end
  199.         if not j.point2.pinned then
  200.             j.point2.x=j.point2.x+offsetX
  201.             j.point2.y=j.point2.y+offsetY
  202.             j.point2.z=j.point2.z+offsetZ
  203.         end
  204.     end
  205. end
  206. local function Swipe()
  207.     swiping=true
  208.     for i=1,6,1 do
  209.         RS.C0=RS.C0*CFrame.Angles(0,0,math.rad(i*10))
  210.         wait()
  211.     end
  212.     for i=1,6,1 do
  213.         RS.C0=RS.C0*CFrame.Angles(0,0,math.rad(-i*15))
  214.         wait()
  215.     end
  216.     for i=1,6,1 do
  217.         RS.C0=RS.C0*CFrame.Angles(0,0,math.rad(i*5))
  218.         wait()
  219.     end
  220.     swiping=false
  221. end
  222. local function StartSpin()
  223.     spinning=true
  224.     for i=1,math.huge do
  225.         if spinning==true then
  226.             T.CFrame=T.CFrame*CFrame.Angles(0,math.rad(50),0)
  227.             wait()
  228.         else
  229.             break
  230.         end
  231.     end
  232. end
  233. local function StopSpin()
  234.     spinning=false
  235. end
  236. mouse.Button1Down:connect(function()
  237.     if not swiping and not slashing and not spinning then
  238.         Swipe()
  239.     end
  240. end)
  241. mouse.KeyDown:connect(function(key)
  242.     if key=="q" then
  243.         if spinning~=true then
  244.             StartSpin()
  245.         else
  246.             spinning=false
  247.         end
  248.     end
  249. end)
  250. game:service'RunService'.Stepped:connect(function()
  251.     handle.CFrame=RA.CFrame*CFrame.new(0.1,-.3,-1.4)
  252.     handle.CFrame=handle.CFrame*CFrame.Angles(-180,0,0)
  253.     for i=1,width do
  254.         local pos=RA.CFrame*CFrame.new(0.3,0.35,-2.5)
  255.         points[i].x=pos.x
  256.         points[i].y=pos.y
  257.         points[i].z=pos.z
  258.     end
  259.     updatePoints()
  260.     for i=1,15 do
  261.         updateSticks()
  262.     end
  263.     drawLine()
  264. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement