Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Edited by iPosterize--
- SETTINGS = {}
- SETTINGS.GRAVITY = 196.2*1
- user = game.Players.LocalPlayer
- repeat wait() until user.Character
- game.StarterGui:SetCoreGuiEnabled(2, false)
- game.StarterGui:SetCoreGuiEnabled(1, false)
- char = user.Character
- mouse = user:GetMouse()
- rootpart = char:WaitForChild("HumanoidRootPart")
- torso = char:WaitForChild("Torso")
- head = char:WaitForChild("Head")
- l_arm = char:WaitForChild("Left Arm")
- r_arm = char:WaitForChild("Right Arm")
- l_leg = char:WaitForChild("Left Leg")
- r_leg = char:WaitForChild("Right Leg")
- Spawn( function()
- wait(.5)
- local function r(p)
- if p:IsA("Sound") then
- p:Destroy()
- end
- for _,v in pairs(p:children()) do
- r(v)
- end
- end
- r(char)
- end)
- Points = {}
- Constraints = {}
- Point = {}
- Point.new = function( x, y, z )
- local self = setmetatable( {}, { __index = Point } )
- self.x = x
- self.y = y
- self.z = z
- self.prevX = x
- self.prevY = y
- self.prevZ = z
- self.velX = 0
- self.velY = 0
- self.velZ = 0
- self.accX = 0
- self.accY = 0
- self.accZ = 0
- self.forceX = 0
- self.forceY = 0
- self.forceZ = 0
- self.pinned = false
- self.mass = 1
- return self
- end
- Point.update = function( self, delta, damp )
- if not self.pinned then
- self.accX = 0
- self.accY = -SETTINGS.GRAVITY
- self.accZ = 0
- self.velX = ( self.x - self.prevX + self.forceX ) --* delta * 30
- self.velY = ( self.y - self.prevY + self.forceY ) --* delta * 30
- self.velZ = ( self.z - self.prevZ + self.forceZ ) --* delta * 30
- local nextX = self.x + self.velX*0.9985*damp + self.accX * delta^2
- local nextY = self.y + self.velY*0.9985*damp + self.accY * delta^2
- local nextZ = self.z + self.velZ*0.9985*damp + self.accZ * delta^2
- self.prevX = self.x
- self.prevY = self.y
- self.prevZ = self.z
- self.x = nextX
- self.y = nextY
- self.z = nextZ
- else
- self.accX = 0
- self.accY = 0
- self.accZ = 0
- self.velX = 0
- self.velY = 0
- self.velZ = 0
- self.prevX = self.x
- self.prevY = self.y
- self.prevZ = self.z
- end
- self.forceX = 0
- self.forceY = 0
- self.forceZ = 0
- end
- Point.setPinned = function(self, pinned)
- self.pinned = pinned
- end
- Point.setMass = function(self, mass)
- self.mass = mass
- end
- Point.getPosition = function( self )
- return Vector3.new( self.x, self.y, self.z )
- end
- Point.setPosition = function( self, pos )
- self.x = pos.x
- self.y = pos.y
- self.z = pos.z
- end
- Point.setForce = function(self, fx, fy, fz)
- self.forceX = fx
- self.forceY = fy
- self.forceZ = fz
- end
- Point.isPinned = function(self)
- return self.pinned
- end
- Constraint = {}
- Constraint.new = function( point1, point2, dist )
- local self = setmetatable( {}, { __index = Constraint } )
- self.point1 = point1
- self.point2 = point2
- self.desireddistance = dist
- self.line = Instance.new("Part", workspace.CurrentCamera)
- self.line.CanCollide = false
- self.line.FormFactor = "Custom"
- self.line.Size = Vector3.new( .2, .2, .2 )
- self.line.Anchored = true
- self.line.BrickColor = BrickColor.new("Institutional white")
- self.mesh = Instance.new("BlockMesh", self.line)
- self.mesh.Scale = Vector3.new( 0.3, 0.3, 5 ) / 0.2
- return self
- end
- Constraint.solve = function( self )
- if not self:isDisconnected() then
- local diffX = self.point1.x - self.point2.x
- local diffY = self.point1.y - self.point2.y
- local diffZ = self.point1.z - self.point2.z
- local dist = math.sqrt( diffX^2 + diffY^2 + diffZ^2 )
- local difference = ( self.desireddistance - dist ) / dist
- local massratio = self.point1.mass/self.point2.mass --?
- local translateX = diffX * 0.5 * difference
- local translateY = diffY * 0.5 * difference
- local translateZ = diffZ * 0.5 * difference
- if not self.point1.pinned then
- self.point1.x = self.point1.x + translateX
- self.point1.y = self.point1.y + translateY
- self.point1.z = self.point1.z + translateZ
- end
- if not self.point2.pinned then
- self.point2.x = self.point2.x - translateX
- self.point2.y = self.point2.y - translateY
- self.point2.z = self.point2.z - translateZ
- end
- end
- end
- Constraint.draw = function( self )
- if not self:isDisconnected() and self.line and self.mesh then
- local dist = math.sqrt(
- ( self.point1.x - self.point2.x )^2 +
- ( self.point1.y - self.point2.y )^2 +
- ( self.point1.z - self.point2.z )^2
- )
- self.line.CFrame = CFrame.new(
- Vector3.new( self.point1.x, self.point1.y, self.point1.z ),
- Vector3.new( self.point2.x, self.point2.y, self.point2.z )
- ) * CFrame.new( 0, 0, - dist / 2 )
- self.mesh.Scale = Vector3.new( 0.3, 0.3, dist ) / 0.2
- end
- end
- Constraint.remove = function( self )
- if self.line then self.line:Destroy() self.line = nil end
- if self.mesh then self.mesh:Destroy() self.mesh = nil end
- self.point1 = nil
- self.point2 = nil
- end
- Constraint.isDisconnected = function( self )
- return not (self.point1 and self.point2)
- end
- Constraint.setDistance = function( self, dist )
- self.desireddistance = dist
- end
- char_point = Point.new( 0, 2300, 0 )
- for _,v in pairs(char.Torso:children()) do
- if v:IsA("Motor6D") and v.Name ~= "Neck" then
- v:Destroy()
- end
- end
- for _,v in pairs(char:children()) do
- if v:IsA("BasePart") then
- v.Anchored = true
- end
- end
- ragdoll = {}
- ragdoll.l_shoulder = Point.new( 0, 0, 0 )
- ragdoll.r_shoulder = Point.new( 0, 0, 0 )
- ragdoll.l_hip = Point.new( 0, 0, 0 )
- ragdoll.r_hip = Point.new( 0, 0, 0 )
- ragdoll.l_shoulder:setPinned( true )
- ragdoll.r_shoulder:setPinned( true )
- ragdoll.l_hip:setPinned( true )
- ragdoll.r_hip:setPinned( true )
- ragdoll.l_arm = Point.new( 0, -2, 0 )
- ragdoll.r_arm = Point.new( 0, -2, 0 )
- ragdoll.l_leg = Point.new( 0, -2, 0 )
- ragdoll.r_leg = Point.new( 0, -2, 0 )
- local l_arm_w = Constraint.new(ragdoll.l_shoulder, ragdoll.l_arm, 2)
- local r_arm_w = Constraint.new(ragdoll.r_shoulder, ragdoll.r_arm, 2)
- local l_leg_w = Constraint.new(ragdoll.l_hip, ragdoll.l_leg, 2)
- local r_leg_w = Constraint.new(ragdoll.r_hip, ragdoll.r_leg, 2)
- firstpoint = nil
- attachpoint = nil
- attachpart = nil
- attachoffset = Vector3.new()
- length = 8
- webshot = false
- local pointbool = false
- function shoot( from, to )
- if not webshot then
- local hit, hitpos = workspace:FindPartOnRay(Ray.new( from, (to-from).unit*999 ), char)
- if hit then
- webshot = true
- to = hitpos
- for _,v in pairs(Constraints) do
- v:remove()
- end
- attachpart = hit
- attachoffset = attachpart.CFrame:pointToObjectSpace( hitpos )
- length = 8
- Constraints = {}
- Points = {}
- local dir = ( to - from ).unit
- local dist = ( to - from ).magnitude
- if dist > 1000 then
- dist = 1000
- to = from + dir*1000
- end
- pointbool = true
- local amnt = math.floor( dist/length )
- amnt = amnt < 2 and 2 or amnt
- local temp = {}
- for y = 1, amnt do
- local pos = from:Lerp( to, y/amnt )
- local rx, ry, rz = ( math.random()-0.5 )*2, ( math.random()-0.5 )*2, ( math.random()-0.5 )*2
- temp[y] = Point.new( pos.x+rx, pos.y+ry, pos.z+rz)
- if y ~= 1 then
- table.insert(Constraints, Constraint.new(temp[y-1], temp[y], length*1) )
- else
- firstpoint = temp[y]
- table.insert(Constraints, Constraint.new(char_point, firstpoint, 1) )
- end
- if y == amnt then
- temp[y]:setPinned(true)
- attachpoint = temp[y]
- end
- end
- for _,p in pairs(temp) do
- table.insert(Points, p)
- end
- end
- else
- attachpart = nil
- attachpoint = nil
- attachoffset = Vector3.new()
- webshot = false
- for _,v in pairs(Constraints) do
- v:remove()
- end
- Constraints = {}
- Points = {}
- end
- end
- keys = {}
- mouse.Button1Down:connect(function()
- shoot( Vector3.new(char_point.x, char_point.y, char_point.z ), mouse.Hit.p )
- end)
- mouse.KeyDown:connect(function(key)
- keys[ string.byte(key) ] = true
- end)
- mouse.KeyUp:connect(function(key)
- keys[ string.byte(key) ] = false
- end)
- prevtime = tick()
- function loop( )
- local delta = tick()-prevtime
- prevtime = tick()
- if keys[32] then
- length = length - 0.1*30*delta
- if length < 2 then length = 2 end
- end
- if keys[48] then
- length = length + 0.1*30*delta
- if length > 11 then length = 11 end
- end
- if attachpart and attachpoint then
- local po = attachpart.CFrame * attachoffset
- attachpoint.x = po.x
- attachpoint.y = po.y
- attachpoint.z = po.z
- end
- char_point:update( delta, 1 )
- if char_point.y < -150 then
- char_point = Point.new( 0, 2200, 0 )
- end
- if pointbool then
- for _,p in pairs(Points) do
- p:setForce( char_point.velX*0.9, char_point.velY*0.9, char_point.velZ*0.9 )
- end
- pointbool = false
- end
- for _,p in pairs(Points) do
- p:update( delta, 1 )
- end
- for _,v in pairs(char:children()) do
- if v:IsA("BasePart") then
- v.Velocity = Vector3.new()
- v.RotVelocity = Vector3.new()
- end
- end
- if firstpoint then
- torso.CFrame = CFrame.new(
- Vector3.new(char_point.x, char_point.y, char_point.z),
- Vector3.new(firstpoint.x, firstpoint.y, firstpoint.z)
- ) * CFrame.Angles(math.rad(-90), 0, 0)
- else
- torso.CFrame = CFrame.new( char_point.x, char_point.y, char_point.z )
- end
- rootpart.CFrame = torso.CFrame
- head.CFrame = torso.CFrame * CFrame.new( 0, 1.5, 0 )
- for _,c in pairs(Constraints) do
- c:setDistance( length )
- end
- local tcf = torso.CFrame
- ragdoll.l_shoulder:setPosition( tcf*CFrame.new( -1.5, 0.5, 0 ).p )
- ragdoll.r_shoulder:setPosition( tcf*CFrame.new( 1.5, 0.5, 0 ).p )
- ragdoll.l_hip:setPosition( tcf*CFrame.new( -0.5, -1, 0 ).p )
- ragdoll.r_hip:setPosition( tcf*CFrame.new( 0.5, -1, 0 ).p )
- for _,v in pairs(ragdoll) do
- v:update( delta, 0.98 )
- end
- for i = 1, 15 do
- for _,c in pairs(Constraints) do
- c:solve()
- end
- l_arm_w:solve()
- r_arm_w:solve()
- l_leg_w:solve()
- r_leg_w:solve()
- end
- for _,c in pairs(Constraints) do
- c:draw()
- end
- l_arm.CFrame = CFrame.new( ragdoll.l_shoulder:getPosition(), ragdoll.l_arm:getPosition() ) * CFrame.Angles(math.pi/2, 0, 0) * CFrame.new( 0, -0.5, 0 )
- r_arm.CFrame = CFrame.new( ragdoll.r_shoulder:getPosition(), ragdoll.r_arm:getPosition() ) * CFrame.Angles(math.pi/2, 0, 0) * CFrame.new( 0, -0.5, 0 )
- l_leg.CFrame = CFrame.new( ragdoll.l_hip:getPosition(), ragdoll.l_leg:getPosition() ) * CFrame.Angles(math.pi/2, 0, 0) * CFrame.new( 0, -1, 0 )
- r_leg.CFrame = CFrame.new( ragdoll.r_hip:getPosition(), ragdoll.r_leg:getPosition() ) * CFrame.Angles(math.pi/2, 0, 0) * CFrame.new( 0, -1, 0 )
- end
- game:getService("RunService").Stepped:connect(loop)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement