Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local next=next
- local gravity=0.09
- local friction=0.85
- 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 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(29) then
- local mesh=Instance.new("SpecialMesh",line)
- mesh.Name="Mesh"
- mesh.MeshType="Sphere"
- 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(29) 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 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=player.Character["Right Arm"].CFrame*CFrame.new(0,0,0)
- points[i].x=p.x
- points[i].y=p.y
- points[i].z=p.z
- end
- 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