Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local next=next
- local gravity=0.09
- local friction=0.7
- local bounce=0.8
- local player=game.Players.LocalPlayer
- local torso=player.Character.Torso
- 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.BrickColor=player.Character.Torso.BrickColor
- line.Anchored=true
- line.CanCollide=false
- line.BottomSurface="Smooth"
- line.TopSurface="Smooth"
- local mesh=Instance.new("BlockMesh",line)
- mesh.Scale=Vector3.new(1,1,1)
- j.line=line
- 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)
- line.Size=Vector3.new(0.1,0.4,distance)
- 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=15
- 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
- if p.y<1 then
- p.y=1
- p.oldy=p.y-vy*bounce;
- end
- 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'.RenderStepped:connect(function()
- for i=1,width do
- local p=torso.CFrame*CFrame.new(0,-0.75,0.45)
- points[i].x=p.x
- points[i].y=p.y
- points[i].z=p.z
- end
- updatePoints()
- for i=1,20 do
- updateSticks()
- end
- drawLine()
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement