Advertisement
Death_Data

Spiderman Swing Script

Jan 1st, 2017
2,417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.47 KB | None | 0 0
  1. --Edited by iPosterize--
  2. SETTINGS = {}
  3. SETTINGS.GRAVITY = 196.2*1
  4.  
  5.  
  6.  
  7.  
  8. user = game.Players.LocalPlayer
  9.  
  10. repeat wait() until user.Character
  11.  
  12. game.StarterGui:SetCoreGuiEnabled(2, false)
  13. game.StarterGui:SetCoreGuiEnabled(1, false)
  14.  
  15. char = user.Character
  16. mouse = user:GetMouse()
  17. rootpart = char:WaitForChild("HumanoidRootPart")
  18. torso = char:WaitForChild("Torso")
  19. head = char:WaitForChild("Head")
  20. l_arm = char:WaitForChild("Left Arm")
  21. r_arm = char:WaitForChild("Right Arm")
  22. l_leg = char:WaitForChild("Left Leg")
  23. r_leg = char:WaitForChild("Right Leg")
  24.  
  25. Spawn( function()
  26. wait(.5)
  27. local function r(p)
  28. if p:IsA("Sound") then
  29. p:Destroy()
  30. end
  31. for _,v in pairs(p:children()) do
  32. r(v)
  33. end
  34. end
  35. r(char)
  36. end)
  37.  
  38. Points = {}
  39. Constraints = {}
  40.  
  41.  
  42.  
  43. Point = {}
  44.  
  45. Point.new = function( x, y, z )
  46. local self = setmetatable( {}, { __index = Point } )
  47.  
  48. self.x = x
  49. self.y = y
  50. self.z = z
  51.  
  52. self.prevX = x
  53. self.prevY = y
  54. self.prevZ = z
  55.  
  56. self.velX = 0
  57. self.velY = 0
  58. self.velZ = 0
  59.  
  60. self.accX = 0
  61. self.accY = 0
  62. self.accZ = 0
  63.  
  64. self.forceX = 0
  65. self.forceY = 0
  66. self.forceZ = 0
  67.  
  68. self.pinned = false
  69. self.mass = 1
  70.  
  71. return self
  72. end
  73.  
  74. Point.update = function( self, delta, damp )
  75.  
  76. if not self.pinned then
  77. self.accX = 0
  78. self.accY = -SETTINGS.GRAVITY
  79. self.accZ = 0
  80.  
  81. self.velX = ( self.x - self.prevX + self.forceX ) --* delta * 30
  82. self.velY = ( self.y - self.prevY + self.forceY ) --* delta * 30
  83. self.velZ = ( self.z - self.prevZ + self.forceZ ) --* delta * 30
  84.  
  85. local nextX = self.x + self.velX*0.9985*damp + self.accX * delta^2
  86. local nextY = self.y + self.velY*0.9985*damp + self.accY * delta^2
  87. local nextZ = self.z + self.velZ*0.9985*damp + self.accZ * delta^2
  88.  
  89. self.prevX = self.x
  90. self.prevY = self.y
  91. self.prevZ = self.z
  92.  
  93. self.x = nextX
  94. self.y = nextY
  95. self.z = nextZ
  96. else
  97. self.accX = 0
  98. self.accY = 0
  99. self.accZ = 0
  100.  
  101. self.velX = 0
  102. self.velY = 0
  103. self.velZ = 0
  104.  
  105. self.prevX = self.x
  106. self.prevY = self.y
  107. self.prevZ = self.z
  108. end
  109.  
  110. self.forceX = 0
  111. self.forceY = 0
  112. self.forceZ = 0
  113. end
  114.  
  115. Point.setPinned = function(self, pinned)
  116. self.pinned = pinned
  117. end
  118.  
  119. Point.setMass = function(self, mass)
  120. self.mass = mass
  121. end
  122.  
  123. Point.getPosition = function( self )
  124. return Vector3.new( self.x, self.y, self.z )
  125. end
  126.  
  127. Point.setPosition = function( self, pos )
  128. self.x = pos.x
  129. self.y = pos.y
  130. self.z = pos.z
  131. end
  132.  
  133. Point.setForce = function(self, fx, fy, fz)
  134. self.forceX = fx
  135. self.forceY = fy
  136. self.forceZ = fz
  137. end
  138.  
  139. Point.isPinned = function(self)
  140. return self.pinned
  141. end
  142.  
  143.  
  144.  
  145. Constraint = {}
  146.  
  147. Constraint.new = function( point1, point2, dist )
  148. local self = setmetatable( {}, { __index = Constraint } )
  149.  
  150. self.point1 = point1
  151. self.point2 = point2
  152.  
  153. self.desireddistance = dist
  154.  
  155. self.line = Instance.new("Part", workspace.CurrentCamera)
  156. self.line.CanCollide = false
  157. self.line.FormFactor = "Custom"
  158. self.line.Size = Vector3.new( .2, .2, .2 )
  159. self.line.Anchored = true
  160. self.line.BrickColor = BrickColor.new("Institutional white")
  161.  
  162. self.mesh = Instance.new("BlockMesh", self.line)
  163. self.mesh.Scale = Vector3.new( 0.3, 0.3, 5 ) / 0.2
  164.  
  165. return self
  166. end
  167.  
  168.  
  169.  
  170. Constraint.solve = function( self )
  171. if not self:isDisconnected() then
  172. local diffX = self.point1.x - self.point2.x
  173. local diffY = self.point1.y - self.point2.y
  174. local diffZ = self.point1.z - self.point2.z
  175.  
  176. local dist = math.sqrt( diffX^2 + diffY^2 + diffZ^2 )
  177.  
  178. local difference = ( self.desireddistance - dist ) / dist
  179.  
  180. local massratio = self.point1.mass/self.point2.mass --?
  181.  
  182. local translateX = diffX * 0.5 * difference
  183. local translateY = diffY * 0.5 * difference
  184. local translateZ = diffZ * 0.5 * difference
  185.  
  186. if not self.point1.pinned then
  187. self.point1.x = self.point1.x + translateX
  188. self.point1.y = self.point1.y + translateY
  189. self.point1.z = self.point1.z + translateZ
  190. end
  191.  
  192. if not self.point2.pinned then
  193. self.point2.x = self.point2.x - translateX
  194. self.point2.y = self.point2.y - translateY
  195. self.point2.z = self.point2.z - translateZ
  196. end
  197. end
  198. end
  199.  
  200. Constraint.draw = function( self )
  201. if not self:isDisconnected() and self.line and self.mesh then
  202. local dist = math.sqrt(
  203. ( self.point1.x - self.point2.x )^2 +
  204. ( self.point1.y - self.point2.y )^2 +
  205. ( self.point1.z - self.point2.z )^2
  206. )
  207.  
  208. self.line.CFrame = CFrame.new(
  209. Vector3.new( self.point1.x, self.point1.y, self.point1.z ),
  210. Vector3.new( self.point2.x, self.point2.y, self.point2.z )
  211. ) * CFrame.new( 0, 0, - dist / 2 )
  212.  
  213. self.mesh.Scale = Vector3.new( 0.3, 0.3, dist ) / 0.2
  214. end
  215. end
  216.  
  217. Constraint.remove = function( self )
  218. if self.line then self.line:Destroy() self.line = nil end
  219. if self.mesh then self.mesh:Destroy() self.mesh = nil end
  220. self.point1 = nil
  221. self.point2 = nil
  222. end
  223.  
  224. Constraint.isDisconnected = function( self )
  225. return not (self.point1 and self.point2)
  226. end
  227.  
  228. Constraint.setDistance = function( self, dist )
  229. self.desireddistance = dist
  230. end
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240. char_point = Point.new( 0, 2300, 0 )
  241.  
  242. for _,v in pairs(char.Torso:children()) do
  243. if v:IsA("Motor6D") and v.Name ~= "Neck" then
  244. v:Destroy()
  245. end
  246. end
  247. for _,v in pairs(char:children()) do
  248. if v:IsA("BasePart") then
  249. v.Anchored = true
  250. end
  251. end
  252.  
  253. ragdoll = {}
  254.  
  255. ragdoll.l_shoulder = Point.new( 0, 0, 0 )
  256. ragdoll.r_shoulder = Point.new( 0, 0, 0 )
  257. ragdoll.l_hip = Point.new( 0, 0, 0 )
  258. ragdoll.r_hip = Point.new( 0, 0, 0 )
  259.  
  260. ragdoll.l_shoulder:setPinned( true )
  261. ragdoll.r_shoulder:setPinned( true )
  262. ragdoll.l_hip:setPinned( true )
  263. ragdoll.r_hip:setPinned( true )
  264.  
  265. ragdoll.l_arm = Point.new( 0, -2, 0 )
  266. ragdoll.r_arm = Point.new( 0, -2, 0 )
  267. ragdoll.l_leg = Point.new( 0, -2, 0 )
  268. ragdoll.r_leg = Point.new( 0, -2, 0 )
  269.  
  270. local l_arm_w = Constraint.new(ragdoll.l_shoulder, ragdoll.l_arm, 2)
  271. local r_arm_w = Constraint.new(ragdoll.r_shoulder, ragdoll.r_arm, 2)
  272. local l_leg_w = Constraint.new(ragdoll.l_hip, ragdoll.l_leg, 2)
  273. local r_leg_w = Constraint.new(ragdoll.r_hip, ragdoll.r_leg, 2)
  274.  
  275.  
  276.  
  277. firstpoint = nil
  278. attachpoint = nil
  279. attachpart = nil
  280. attachoffset = Vector3.new()
  281.  
  282. length = 8
  283.  
  284. webshot = false
  285. local pointbool = false
  286.  
  287. function shoot( from, to )
  288. if not webshot then
  289. local hit, hitpos = workspace:FindPartOnRay(Ray.new( from, (to-from).unit*999 ), char)
  290. if hit then
  291. webshot = true
  292. to = hitpos
  293. for _,v in pairs(Constraints) do
  294. v:remove()
  295. end
  296.  
  297. attachpart = hit
  298. attachoffset = attachpart.CFrame:pointToObjectSpace( hitpos )
  299.  
  300. length = 8
  301.  
  302. Constraints = {}
  303. Points = {}
  304.  
  305. local dir = ( to - from ).unit
  306. local dist = ( to - from ).magnitude
  307. if dist > 1000 then
  308. dist = 1000
  309. to = from + dir*1000
  310. end
  311.  
  312. pointbool = true
  313.  
  314. local amnt = math.floor( dist/length )
  315. amnt = amnt < 2 and 2 or amnt
  316. local temp = {}
  317.  
  318. for y = 1, amnt do
  319. local pos = from:Lerp( to, y/amnt )
  320.  
  321. local rx, ry, rz = ( math.random()-0.5 )*2, ( math.random()-0.5 )*2, ( math.random()-0.5 )*2
  322. temp[y] = Point.new( pos.x+rx, pos.y+ry, pos.z+rz)
  323.  
  324. if y ~= 1 then
  325. table.insert(Constraints, Constraint.new(temp[y-1], temp[y], length*1) )
  326. else
  327. firstpoint = temp[y]
  328. table.insert(Constraints, Constraint.new(char_point, firstpoint, 1) )
  329. end
  330.  
  331. if y == amnt then
  332. temp[y]:setPinned(true)
  333. attachpoint = temp[y]
  334. end
  335. end
  336.  
  337. for _,p in pairs(temp) do
  338. table.insert(Points, p)
  339. end
  340. end
  341. else
  342. attachpart = nil
  343. attachpoint = nil
  344. attachoffset = Vector3.new()
  345.  
  346. webshot = false
  347. for _,v in pairs(Constraints) do
  348. v:remove()
  349. end
  350.  
  351. Constraints = {}
  352. Points = {}
  353.  
  354. end
  355. end
  356.  
  357. keys = {}
  358.  
  359. mouse.Button1Down:connect(function()
  360. shoot( Vector3.new(char_point.x, char_point.y, char_point.z ), mouse.Hit.p )
  361. end)
  362.  
  363. mouse.KeyDown:connect(function(key)
  364. keys[ string.byte(key) ] = true
  365. end)
  366. mouse.KeyUp:connect(function(key)
  367. keys[ string.byte(key) ] = false
  368. end)
  369.  
  370. prevtime = tick()
  371.  
  372. function loop( )
  373. local delta = tick()-prevtime
  374. prevtime = tick()
  375.  
  376. if keys[32] then
  377. length = length - 0.1*30*delta
  378. if length < 2 then length = 2 end
  379. end
  380. if keys[48] then
  381. length = length + 0.1*30*delta
  382. if length > 11 then length = 11 end
  383. end
  384.  
  385. if attachpart and attachpoint then
  386. local po = attachpart.CFrame * attachoffset
  387. attachpoint.x = po.x
  388. attachpoint.y = po.y
  389. attachpoint.z = po.z
  390. end
  391.  
  392. char_point:update( delta, 1 )
  393. if char_point.y < -150 then
  394. char_point = Point.new( 0, 2200, 0 )
  395. end
  396.  
  397. if pointbool then
  398. for _,p in pairs(Points) do
  399. p:setForce( char_point.velX*0.9, char_point.velY*0.9, char_point.velZ*0.9 )
  400. end
  401. pointbool = false
  402. end
  403.  
  404. for _,p in pairs(Points) do
  405. p:update( delta, 1 )
  406. end
  407.  
  408. for _,v in pairs(char:children()) do
  409. if v:IsA("BasePart") then
  410. v.Velocity = Vector3.new()
  411. v.RotVelocity = Vector3.new()
  412. end
  413. end
  414.  
  415. if firstpoint then
  416. torso.CFrame = CFrame.new(
  417. Vector3.new(char_point.x, char_point.y, char_point.z),
  418. Vector3.new(firstpoint.x, firstpoint.y, firstpoint.z)
  419. ) * CFrame.Angles(math.rad(-90), 0, 0)
  420. else
  421. torso.CFrame = CFrame.new( char_point.x, char_point.y, char_point.z )
  422. end
  423. rootpart.CFrame = torso.CFrame
  424. head.CFrame = torso.CFrame * CFrame.new( 0, 1.5, 0 )
  425. for _,c in pairs(Constraints) do
  426. c:setDistance( length )
  427. end
  428.  
  429. local tcf = torso.CFrame
  430. ragdoll.l_shoulder:setPosition( tcf*CFrame.new( -1.5, 0.5, 0 ).p )
  431. ragdoll.r_shoulder:setPosition( tcf*CFrame.new( 1.5, 0.5, 0 ).p )
  432. ragdoll.l_hip:setPosition( tcf*CFrame.new( -0.5, -1, 0 ).p )
  433. ragdoll.r_hip:setPosition( tcf*CFrame.new( 0.5, -1, 0 ).p )
  434.  
  435. for _,v in pairs(ragdoll) do
  436. v:update( delta, 0.98 )
  437. end
  438.  
  439. for i = 1, 15 do
  440. for _,c in pairs(Constraints) do
  441. c:solve()
  442. end
  443. l_arm_w:solve()
  444. r_arm_w:solve()
  445. l_leg_w:solve()
  446. r_leg_w:solve()
  447. end
  448. for _,c in pairs(Constraints) do
  449. c:draw()
  450. end
  451.  
  452. 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 )
  453. 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 )
  454. 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 )
  455. 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 )
  456.  
  457. end
  458.  
  459. game:getService("RunService").Stepped:connect(loop)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement