Advertisement
jordan83221

Balloon Flight

Mar 25th, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.50 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 speed=100
  24. local function dist(p0,p1)
  25.     local dx=p1.CFrame.x-p0.CFrame.x
  26.     local dy=p1.CFrame.y-p0.CFrame.y
  27.     local dz=p1.CFrame.z-p0.CFrame.z
  28.     return math.sqrt(dx*dx+dy*dy+dz*dz)
  29. end
  30. local points={}
  31. local joints={}
  32. local function createPoint(x,y,z,pinned)
  33.     local t = {x=x,y=y,z=z,oldx=x-0.4,oldy=y-0.4,oldz=z-0.4,pinned=pinned}
  34.     points[#points+1]=t
  35.     return t
  36. end
  37. local function createJoint(point1,point2,distance,line)
  38.     local t = {point1=point1,point2=point2,distance=distance,line=line}
  39.     table.insert(joints,t)
  40. end
  41. local tool=Instance.new("HopperBin",game.Players.LocalPlayer.Backpack)
  42. tool.Name="FlyThing"
  43. local function drawLine()
  44.     for i=1,#joints do
  45.         local j=joints[i]
  46.         local line=j.line
  47.         if not line then
  48.             line=Instance.new("Part",player.Character)
  49.             line.Name=tostring(i)
  50.             line.Anchored=true
  51.             line.CanCollide=false
  52.             line.BottomSurface="Smooth"
  53.             line.TopSurface="Smooth"
  54.             j.line=line
  55.             if line.Name==tostring(1) then
  56.                 local mesh=Instance.new("SpecialMesh",line)
  57.                 mesh.Name="Mesh"
  58.                 mesh.MeshType="Sphere"
  59.                 coroutine.resume(coroutine.create(function()
  60.                     tool.Selected:connect(function(mouse)
  61.                         local bv=Instance.new("BodyVelocity",drag)
  62.                         bv.maxForce=Vector3.new(0,math.huge,0)
  63.                         bv.Velocity=Vector3.new(0,0,0)
  64.                         bv.Parent=drag
  65.                         local bg=Instance.new("BodyGyro",drag)
  66.                         bg.maxTorque=Vector3.new(0,0,0)
  67.                         bg.Parent=drag
  68.                         drag.Anchored=false
  69.                         connection = mouse.Button1Down:connect(function()
  70.                             deselected=false
  71.                             bv.maxForce=Vector3.new(math.huge,math.huge,math.huge)
  72.                             bg.maxTorque=Vector3.new(900000,900000,900000)
  73.                             bg.CFrame=CFrame.new(drag.Position,mouse.hit.p)*CFrame.Angles(math.rad(-90),0,0)
  74.                             bv.Velocity=CFrame.new(drag.Position,mouse.hit.p).lookVector*speed
  75.                             moveconnect=mouse.Move:connect(function()
  76.                                 bg.maxTorque=Vector3.new(90000,900000,900000)
  77.                                 bg.CFrame=CFrame.new(drag.Position,mouse.hit.p)*CFrame.Angles(math.rad(-90),0,0)
  78.                                 bv.Velocity=CFrame.new(drag.Position,mouse.hit.p).lookVector*speed
  79.                             end)
  80.                             upconnect=mouse.Button1Up:connect(function()
  81.                                 deselected=true
  82.                                 moveconnect:disconnect()
  83.                                 upconnect:disconnect()
  84.                                 bv.Velocity=Vector3.new(0,0,0)
  85.                                 bv.maxForce=Vector3.new(0,math.huge,0)
  86.                                 drag.Velocity=Vector3.new(0,0,0)
  87.                                 bg.CFrame=CFrame.new(drag.Position,drag.Position+Vector3.new(drag.CFrame.lookVector.x,0,drag.CFrame.lookVector.z))
  88.                                 wait(1)
  89.                             end)
  90.                         end)
  91.                         tool.Deselected:connect(function()
  92.                             deselected=true
  93.                             connection:disconnect()
  94.                             bv:Destroy()
  95.                             bg:Destroy()
  96.                             drag.Anchored=true
  97.                         end)
  98.                     end)
  99.                 end))
  100.             else
  101.                 local mesh=Instance.new("BlockMesh",line)
  102.                 mesh.Scale=Vector3.new(1,1,1)
  103.             end
  104.         end
  105.         local dx=j.point2.x-j.point1.x
  106.         local dy=j.point2.y-j.point1.y
  107.         local dz=j.point2.z-j.point1.z
  108.         local distance=math.sqrt(dx*dx+dy*dy+dz*dz)
  109.         if line.Name==tostring(1) then
  110.             line.BrickColor=BrickColor.new("Really red")
  111.             line.Size=Vector3.new(3, 3, 3.6)
  112.         else
  113.             line.BrickColor=BrickColor.new("Gold")
  114.             line.Size=Vector3.new(0.1,0.4,distance)
  115.         end
  116.         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))
  117.         *CFrame.new(0,0,-distance/2)
  118.     end
  119. end
  120. local width=1
  121. local height=30
  122. local l=0.25
  123. for y=1,height do
  124.     for x=1,width do
  125.         createPoint(l*x,25-l*y,0,y==1)
  126.         if x>1 then
  127.             createJoint(points[width*(y-1)+x-1],points[width*(y-1)+x],l)
  128.         end
  129.         if y>1 then
  130.             createJoint(points[width*(y-2)+x],points[width*(y-1)+x],l)
  131.         end
  132.     end
  133. end
  134. --[[local rlad=dist(RA,LA)
  135. local rlld=dist(RL,LL)
  136. local rlald=dist(RA,LL)
  137. local rllad=dist(LA,RL)
  138. local rrla=dist(RA,RL)
  139. local llla=dist(LL,LA)
  140. local rat=dist(RA,torso)
  141. local lat=dist(LA,torso)
  142. local rlt=dist(RL,torso)
  143. local llt=dist(LL,torso)
  144. local ra1=createPoint(RA.CFrame.X,RA.CFrame.Y,RA.CFrame.Z,false)
  145. local la1=createPoint(LA.CFrame.X,LA.CFrame.Y,LA.CFrame.Z,false)
  146. local rl1=createPoint(RL.CFrame.X,RL.CFrame.Y,RL.CFrame.Z,false)
  147. local ll1=createPoint(LL.CFrame.X,LL.CFrame.Y,LL.CFrame.Z,false)
  148. local tt=createPoint(torso.CFrame.X,torso.CFrame.Y,torso.CFrame.Z,false)
  149. createJoint(ra1,la1,rlad)
  150. createJoint(rl1,ll1,rlld)
  151. createJoint(tt,ra1,rat)
  152. createJoint(tt,la1,lat)
  153. createJoint(]]
  154. local function updatePoints()
  155.     for i=1,#points do
  156.         local p=points[i]
  157.         if not p.pinned then
  158.             local vx=(p.x-p.oldx)*friction;
  159.             local vy=-((p.y-p.oldy)*friction);
  160.             local vz=(p.z-p.oldz)*friction;
  161.             p.oldx=p.x
  162.             p.oldy=p.y
  163.             p.oldz=p.z
  164.             p.x=p.x+vx
  165.             p.y=p.y-vy
  166.             p.z=p.z+vz
  167.             p.y=p.y-gravity
  168.         end
  169.     end
  170. end
  171. local function updateSticks()
  172.     for i=1,#joints do
  173.         local j=joints[i]
  174.         local dx=j.point2.x-j.point1.x
  175.         local dy=j.point2.y-j.point1.y
  176.         local dz=j.point2.z-j.point1.z
  177.         local distance=math.sqrt(dx*dx+dy*dy+dz*dz)
  178.         local difference=j.distance-distance
  179.         local percent=difference/distance/2
  180.         local offsetX=dx*percent;
  181.         local offsetY=dy*percent;
  182.         local offsetZ=dz*percent;
  183.         if j.point1.pinned or j.point2.pinned then
  184.             offsetX=offsetX*2
  185.             offsetY=offsetY*2
  186.             offsetZ=offsetZ*2
  187.         end
  188.         if not j.point1.pinned then
  189.             j.point1.x=j.point1.x-offsetX
  190.             j.point1.y=j.point1.y-offsetY
  191.             j.point1.z=j.point1.z-offsetZ
  192.         end
  193.         if not j.point2.pinned then
  194.             j.point2.x=j.point2.x+offsetX
  195.             j.point2.y=j.point2.y+offsetY
  196.             j.point2.z=j.point2.z+offsetZ
  197.         end
  198.     end
  199. end
  200. game:service'RunService'.Stepped:connect(function()
  201.     for i=1,width do
  202.         local p=drag.CFrame
  203.         points[i].x=p.x
  204.         points[i].y=p.y
  205.         points[i].z=p.z
  206.     end
  207.     local p=player.Character.HumanoidRootPart
  208.     p.Anchored=true
  209.     p.CFrame=CFrame.new(points[29].x+1.8,points[29].y-2,points[29].z+0.4)
  210.     updatePoints()
  211.     for i=1,10 do
  212.         updateSticks()
  213.     end
  214.     drawLine()
  215.     coroutine.resume(coroutine.create(function()
  216.         if deselected then
  217.             drag.CFrame=drag.CFrame*CFrame.new(0,math.sin(tick()*2)/15,0)
  218.         end
  219.     end))
  220. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement