Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local next=next
- local gravity=0.09
- local friction=0.9
- local bounce=0.8
- local drag=Instance.new("Part",workspace)
- drag.Name="Dragger"
- drag.Anchored=true
- drag.CanCollide=false
- drag.Locked=true
- deselected=true
- drag.Transparency=1
- drag.Position=Vector3.new(0,50,0)
- local player=game.Players.LocalPlayer
- local char=player.Character
- local torso=player.Character.Torso
- local humanoid=player.Character.Humanoid
- local head=player.Character.Head
- local camera=workspace.CurrentCamera
- local RA=char["Right Arm"]
- local LA=char["Left Arm"]
- local RL=char["Right Leg"]
- local LL=char["Left Leg"]
- local speed=100
- local function dist(p0,p1)
- local dx=p1.CFrame.x-p0.CFrame.x
- local dy=p1.CFrame.y-p0.CFrame.y
- local dz=p1.CFrame.z-p0.CFrame.z
- return math.sqrt(dx*dx+dy*dy+dz*dz)
- end
- local points={}
- local joints={}
- local function createPoint(x,y,z,pinned)
- local t = {x=x,y=y,z=z,oldx=x-0.4,oldy=y-0.4,oldz=z-0.4,pinned=pinned}
- points[#points+1]=t
- return t
- end
- local function createJoint(point1,point2,distance,line)
- local t = {point1=point1,point2=point2,distance=distance,line=line}
- table.insert(joints,t)
- end
- local tool=Instance.new("HopperBin",game.Players.LocalPlayer.Backpack)
- tool.Name="FlyThing"
- local function drawLine()
- for i=1,#joints do
- local j=joints[i]
- local line=j.line
- if not line then
- line=Instance.new("Part",player.Character)
- line.Name=tostring(i)
- line.Anchored=true
- line.CanCollide=false
- line.BottomSurface="Smooth"
- line.TopSurface="Smooth"
- j.line=line
- if line.Name==tostring(1) then
- local mesh=Instance.new("SpecialMesh",line)
- mesh.Name="Mesh"
- mesh.MeshType="Sphere"
- coroutine.resume(coroutine.create(function()
- tool.Selected:connect(function(mouse)
- local bv=Instance.new("BodyVelocity",drag)
- bv.maxForce=Vector3.new(0,math.huge,0)
- bv.Velocity=Vector3.new(0,0,0)
- bv.Parent=drag
- local bg=Instance.new("BodyGyro",drag)
- bg.maxTorque=Vector3.new(0,0,0)
- bg.Parent=drag
- drag.Anchored=false
- connection = mouse.Button1Down:connect(function()
- deselected=false
- bv.maxForce=Vector3.new(math.huge,math.huge,math.huge)
- bg.maxTorque=Vector3.new(900000,900000,900000)
- bg.CFrame=CFrame.new(drag.Position,mouse.hit.p)*CFrame.Angles(math.rad(-90),0,0)
- bv.Velocity=CFrame.new(drag.Position,mouse.hit.p).lookVector*speed
- moveconnect=mouse.Move:connect(function()
- bg.maxTorque=Vector3.new(90000,900000,900000)
- bg.CFrame=CFrame.new(drag.Position,mouse.hit.p)*CFrame.Angles(math.rad(-90),0,0)
- bv.Velocity=CFrame.new(drag.Position,mouse.hit.p).lookVector*speed
- end)
- upconnect=mouse.Button1Up:connect(function()
- deselected=true
- moveconnect:disconnect()
- upconnect:disconnect()
- bv.Velocity=Vector3.new(0,0,0)
- bv.maxForce=Vector3.new(0,math.huge,0)
- drag.Velocity=Vector3.new(0,0,0)
- bg.CFrame=CFrame.new(drag.Position,drag.Position+Vector3.new(drag.CFrame.lookVector.x,0,drag.CFrame.lookVector.z))
- wait(1)
- end)
- end)
- tool.Deselected:connect(function()
- deselected=true
- connection:disconnect()
- bv:Destroy()
- bg:Destroy()
- drag.Anchored=true
- end)
- end)
- end))
- else
- local mesh=Instance.new("BlockMesh",line)
- mesh.Scale=Vector3.new(1,1,1)
- end
- end
- local dx=j.point2.x-j.point1.x
- local dy=j.point2.y-j.point1.y
- local dz=j.point2.z-j.point1.z
- local distance=math.sqrt(dx*dx+dy*dy+dz*dz)
- if line.Name==tostring(1) then
- line.BrickColor=BrickColor.new("Really red")
- line.Size=Vector3.new(3, 3, 3.6)
- else
- line.BrickColor=BrickColor.new("Gold")
- line.Size=Vector3.new(0.1,0.4,distance)
- end
- 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.new(0,0,-distance/2)
- end
- end
- local width=1
- local height=30
- local l=0.25
- for y=1,height do
- for x=1,width do
- createPoint(l*x,25-l*y,0,y==1)
- if x>1 then
- createJoint(points[width*(y-1)+x-1],points[width*(y-1)+x],l)
- end
- if y>1 then
- createJoint(points[width*(y-2)+x],points[width*(y-1)+x],l)
- end
- end
- end
- --[[local rlad=dist(RA,LA)
- local rlld=dist(RL,LL)
- local rlald=dist(RA,LL)
- local rllad=dist(LA,RL)
- local rrla=dist(RA,RL)
- local llla=dist(LL,LA)
- local rat=dist(RA,torso)
- local lat=dist(LA,torso)
- local rlt=dist(RL,torso)
- local llt=dist(LL,torso)
- local ra1=createPoint(RA.CFrame.X,RA.CFrame.Y,RA.CFrame.Z,false)
- local la1=createPoint(LA.CFrame.X,LA.CFrame.Y,LA.CFrame.Z,false)
- local rl1=createPoint(RL.CFrame.X,RL.CFrame.Y,RL.CFrame.Z,false)
- local ll1=createPoint(LL.CFrame.X,LL.CFrame.Y,LL.CFrame.Z,false)
- local tt=createPoint(torso.CFrame.X,torso.CFrame.Y,torso.CFrame.Z,false)
- createJoint(ra1,la1,rlad)
- createJoint(rl1,ll1,rlld)
- createJoint(tt,ra1,rat)
- createJoint(tt,la1,lat)
- createJoint(]]
- local function updatePoints()
- for i=1,#points do
- local p=points[i]
- if not p.pinned then
- local vx=(p.x-p.oldx)*friction;
- local vy=-((p.y-p.oldy)*friction);
- local vz=(p.z-p.oldz)*friction;
- p.oldx=p.x
- p.oldy=p.y
- p.oldz=p.z
- p.x=p.x+vx
- p.y=p.y-vy
- p.z=p.z+vz
- p.y=p.y-gravity
- end
- end
- end
- local function updateSticks()
- for i=1,#joints do
- local j=joints[i]
- local dx=j.point2.x-j.point1.x
- local dy=j.point2.y-j.point1.y
- local dz=j.point2.z-j.point1.z
- local distance=math.sqrt(dx*dx+dy*dy+dz*dz)
- local difference=j.distance-distance
- local percent=difference/distance/2
- local offsetX=dx*percent;
- local offsetY=dy*percent;
- local offsetZ=dz*percent;
- if j.point1.pinned or j.point2.pinned then
- offsetX=offsetX*2
- offsetY=offsetY*2
- offsetZ=offsetZ*2
- end
- if not j.point1.pinned then
- j.point1.x=j.point1.x-offsetX
- j.point1.y=j.point1.y-offsetY
- j.point1.z=j.point1.z-offsetZ
- end
- if not j.point2.pinned then
- j.point2.x=j.point2.x+offsetX
- j.point2.y=j.point2.y+offsetY
- j.point2.z=j.point2.z+offsetZ
- end
- end
- end
- game:service'RunService'.Stepped:connect(function()
- for i=1,width do
- local p=drag.CFrame
- points[i].x=p.x
- points[i].y=p.y
- points[i].z=p.z
- end
- local p=player.Character.HumanoidRootPart
- p.Anchored=true
- p.CFrame=CFrame.new(points[29].x+1.8,points[29].y-2,points[29].z+0.4)
- updatePoints()
- for i=1,10 do
- updateSticks()
- end
- drawLine()
- coroutine.resume(coroutine.create(function()
- if deselected then
- drag.CFrame=drag.CFrame*CFrame.new(0,math.sin(tick()*2)/15,0)
- end
- end))
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement