Advertisement
BobMe

HeliPack

Jan 1st, 2018
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.81 KB | None | 0 0
  1. --PUT IN STARTER GUI
  2. --All credit goes to xSoulStealerx
  3.  
  4.  
  5.  
  6. create = function( tab )
  7. local obj = Instance.new( tab[1] )
  8. for i, v in pairs( tab ) do
  9. if i ~= 1 then
  10. obj[i] = v
  11. end
  12. end
  13. if obj:IsA("BasePart") then
  14. obj:breakJoints()
  15. end
  16. return obj
  17. end
  18.  
  19. local player = game.Players.LocalPlayer
  20.  
  21. repeat wait() until player.Character
  22.  
  23. local _sgui = create{ "ScreenGui", Parent = player.PlayerGui, Name = "Controls" }
  24. local _txt = create{ "TextLabel", Parent = _sgui, Text = "Start/Stop:\t\t\tdouble-tap spacebar\nThrust:\t\t\t\thold spacebar\nTurn character:\trotate camera\nTilt offset:\t\t\tWASD\n\nCaution: may be hard to control for some people\nTip: hold space only when you feel like you need more force upwards",
  25. BackgroundTransparency = 1, TextColor3 = Color3.new(), Size = UDim2.new(0,0,0,0),
  26. Position = UDim2.new(0.5, -70, 0, 15), TextWrap = true, TextXAlignment = "Left", TextYAlignment = "Top"
  27. }
  28.  
  29. local character = player.Character
  30. local humanoid = character:WaitForChild("Humanoid")
  31. local head = character:WaitForChild("Head")
  32. local torso = character:WaitForChild("Torso")
  33. local l_arm = character:WaitForChild("Left Arm")
  34. local r_arm = character:WaitForChild("Right Arm")
  35. local l_leg = character:WaitForChild("Left Leg")
  36. local r_leg = character:WaitForChild("Right Leg")
  37.  
  38. game:service("ContentProvider"):Preload("rbxassetid://134145308")
  39.  
  40. local heli_sound = create{ "Sound", SoundId = "rbxassetid://134145308", Volume = 0.15, Looped = true }
  41.  
  42. local mouse = player:GetMouse()
  43. local camera = workspace.CurrentCamera
  44. local bodymass = 0
  45.  
  46. local heli_axis_weld;
  47. local heli_rotor_weld;
  48. local heli_rotorspeed;
  49. local heli_rotorrot;
  50. local heli_targetthrottle;
  51. local heli_throttle;
  52.  
  53. local collision_time;
  54.  
  55. local bodyforce;
  56. local bodygyro;
  57. local tilt = CFrame.new();
  58.  
  59. local fake_l_arm;
  60. local fake_r_arm;
  61. local fake_l_leg;
  62. local fake_r_leg;
  63. local heli_axeltop;
  64. local heli_axel;
  65. local heli_top;
  66.  
  67. local getMass;
  68. local updateMass;
  69. local openPack;
  70. local closePack;
  71.  
  72. local pack_open = false;
  73.  
  74. local lastSpaceTick;
  75.  
  76. keys = {}
  77. framekeys = {}
  78.  
  79. mouse.KeyDown:connect( function(key)
  80. keys[ string.byte(key) ] = true
  81. framekeys[ string.byte(key) ] = true
  82. end )
  83. mouse.KeyUp:connect( function(key)
  84. keys[ string.byte(key) ] = false
  85. framekeys[ string.byte(key) ] = false
  86. end )
  87.  
  88. lastSpaceTick = 0
  89.  
  90. handleInput = function()
  91. if keys[32] == true then
  92. heli_targetthrottle = 1.5
  93. else
  94. heli_targetthrottle = 0.7
  95. end
  96. if not pack_open then
  97. heli_targetthrottle = 0
  98. end
  99. local t = CFrame.new()
  100. if keys[ string.byte'a' ] then
  101. t = t * CFrame.Angles( 0, 0, math.rad(25) )
  102. end
  103. if keys[ string.byte'd' ] then
  104. t = t * CFrame.Angles( 0, 0, math.rad(-25) )
  105. end
  106. if keys[ string.byte'w' ] then
  107. t = t * CFrame.Angles( math.rad(-25), 0, 0 )
  108. end
  109. if keys[ string.byte's' ] then
  110. t = t * CFrame.Angles( math.rad(25), 0, 0 )
  111. end
  112. tilt = t
  113. if framekeys[32] == true then
  114. if tick() - lastSpaceTick < 0.3 then
  115. lastSpaceTick = 0
  116. if pack_open then closePack() else openPack() end
  117. else
  118. lastSpaceTick = tick()
  119. end
  120. end
  121. end
  122.  
  123. openPack = function()
  124. pack_open = true
  125. heli_throttle = 0.6
  126. heli_sound:Stop()
  127. heli_sound:Play()
  128. humanoid.PlatformStand = true
  129. bodygyro.Parent = heli_top
  130. fake_l_arm.CanCollide = true
  131. fake_r_arm.CanCollide = true
  132. fake_l_leg.CanCollide = true
  133. fake_r_leg.CanCollide = true
  134. game:service("ControllerService"):ClearAllChildren()
  135. end
  136. closePack = function()
  137. pack_open = false
  138. humanoid.PlatformStand = false
  139. bodygyro.Parent = nil
  140. fake_l_arm.CanCollide = false
  141. fake_r_arm.CanCollide = false
  142. fake_l_leg.CanCollide = false
  143. fake_r_leg.CanCollide = false
  144.  
  145. coroutine.resume(coroutine.create(function()
  146. wait(0.2)
  147. Instance.new("HumanoidController",game:service("ControllerService"))
  148. end))
  149. end
  150.  
  151. getMass = function( p )
  152. local mass = 0
  153. if p:IsA("BasePart") then
  154. mass = mass + p:GetMass()
  155. end
  156. for _, child in pairs( p:children() ) do
  157. mass = mass + getMass( child )
  158. end
  159. return mass
  160. end
  161.  
  162. updateMass = function()
  163. bodymass = getMass( character )
  164. end
  165.  
  166. collision_time = 0
  167.  
  168. onCollision = function( hit )
  169. if collision_time <= 0 then
  170. local hit_speed = ( torso.Velocity - hit.Velocity ).magnitude
  171. if hit_speed > 65 and hit.CanCollide == true then
  172. collision_time = 0.8
  173. bodygyro.Parent = nil
  174. end
  175. end
  176. end
  177.  
  178. torso.Touched:connect( onCollision )
  179. head.Touched:connect( onCollision )
  180.  
  181. for _, child in pairs( character:children() ) do
  182. if child.Name == "HeliPack" then
  183. child:Destroy()
  184. end
  185. end
  186.  
  187. heli_model = create{ "Model", Name = "HeliPack", Parent = character }
  188. script.Parent = heli_model
  189.  
  190. fake_l_arm = create { "Part", Parent = heli_model, FormFactor = "Custom", Size = Vector3.new(1,2,1), CanCollide = true, Transparency = 1, Elasticity = 0.1, Friction = 0.8 }
  191. fake_r_arm = create { "Part", Parent = heli_model, FormFactor = "Custom", Size = Vector3.new(1,2,1), CanCollide = true, Transparency = 1, Elasticity = 0.1, Friction = 0.8 }
  192. fake_l_leg = create { "Part", Parent = heli_model, FormFactor = "Custom", Size = Vector3.new(1,2,1), CanCollide = true, Transparency = 1, Elasticity = 0.1, Friction = 0.8 }
  193. fake_r_leg = create { "Part", Parent = heli_model, FormFactor = "Custom", Size = Vector3.new(1,2,1), CanCollide = true, Transparency = 1, Elasticity = 0.1, Friction = 0.8 }
  194. create{ "Weld", Part0 = l_arm, Part1 = fake_l_arm, Parent = character }
  195. create{ "Weld", Part0 = r_arm, Part1 = fake_r_arm, Parent = character }
  196. create{ "Weld", Part0 = l_leg, Part1 = fake_l_leg, Parent = character }
  197. create{ "Weld", Part0 = r_leg, Part1 = fake_r_leg, Parent = character }
  198.  
  199. fake_l_arm.Touched:connect( onCollision )
  200. fake_r_arm.Touched:connect( onCollision )
  201. fake_l_leg.Touched:connect( onCollision )
  202. fake_r_leg.Touched:connect( onCollision )
  203.  
  204. heli_base = create{ "Part", TopSurface = 0, BottomSurface = 0, FormFactor = "Custom", Parent = heli_model,
  205. Size = Vector3.new(1.8, 1.8, 0.2), BrickColor = BrickColor.new(1002)
  206. }
  207. heli_motor = create{ "Part", TopSurface = 0, BottomSurface = 0, FormFactor = "Custom", Parent = heli_model,
  208. Size = Vector3.new(1.8, 1.7, 0.6), BrickColor = BrickColor.new(194)
  209. }
  210. heli_axel = create{ "Part", TopSurface = 0, BottomSurface = 0, FormFactor = "Custom", Parent = heli_model, CanCollide = false,
  211. Size = Vector3.new(0.2, 3.1, 0.2), BrickColor = BrickColor.new(1002)
  212. }
  213. local _hp = create{ "Part", Parent = heli_model, TopSurface = 0, BottomSurface = 0, FormFactor = "Custom", CanCollide = false, Size = Vector3.new(0.4, 0.2, 0.4), BrickColor = BrickColor.new("Black") }
  214. create{ "CylinderMesh", Parent = _hp}
  215. create{"Weld", Parent = heli_model, Part0 = heli_motor, Part1 = _hp, C0 = CFrame.new(0, 0.9, 0) }
  216. heli_axeltop = create{ "Part", TopSurface = 0, BottomSurface = 0, FormFactor = "Custom", Parent = heli_model, CanCollide = false,
  217. Size = Vector3.new(0.4, 0.2, 0.4), BrickColor = BrickColor.new("Black")
  218. }
  219. heli_top = create{ "Part", TopSurface = 0, BottomSurface = 0, FormFactor = "Custom", Parent = heli_model, CanCollide = false,
  220. Size = Vector3.new(0.2, 0.2, 0.2), Transparency = 1
  221. }
  222. create{ "Weld", Part0 = heli_axel, Part1 = heli_top, C0 = CFrame.new(0,1.5,0), Parent = heli_model }
  223.  
  224. create{ "CylinderMesh", Parent = heli_axeltop }
  225. create{ "CylinderMesh", Parent = heli_axel }
  226.  
  227. heli_rotor_weld = create{ "Weld", Parent = heli_model, Part0 = heli_axel, Part1 = heli_axeltop, C0 = CFrame.new(0,1.6,0) }
  228.  
  229. clone_rotor = create{ "Part", TopSurface = 0, BottomSurface = 0, FormFactor = "Custom", CanCollide = false,
  230. Size = Vector3.new(1.1, 0.2, 4.5), Transparency = 1
  231. }
  232. create { "Decal", Parent = clone_rotor, Texture = "rbxassetid://142889819", Face = "Top" }
  233. create { "Decal", Parent = clone_rotor, Texture = "rbxassetid://142889819", Face = "Bottom" }
  234.  
  235. for angle = 0, 360-120, 120 do
  236. local part = clone_rotor:clone()
  237. create{ "BlockMesh", Parent = part, Scale = Vector3.new(1,0,1) }
  238. create{ "Weld", Part0 = heli_axeltop, Part1 = part, C0 = CFrame.Angles(0, math.rad(angle), 0), C1 = CFrame.new( 0, 0, -2.25 ), Parent = heli_model }
  239. part.Parent = heli_model
  240. end
  241.  
  242. create{ "Weld", Part0 = torso, Part1 = heli_base, C0 = CFrame.new( 0, 0, 0.6 ), Parent = heli_model }
  243. create{ "Weld", Part0 = heli_base, Part1 = heli_motor, C0 = CFrame.new( 0, -0.05, 0.4 ), Parent = heli_model }
  244.  
  245. heli_axis_weld = create{ "Weld", Part0 = heli_motor, Part1 = heli_axel, C0 = CFrame.new( 0, 2.3, 0 ), Parent = heli_model }
  246.  
  247. heli_l_part = create{ "Part", TopSurface = 0, BottomSurface = 0, FormFactor = "Custom", Parent = heli_model, CanCollide = false, Size = Vector3.new(0.2, 1, 0.2), BrickColor = BrickColor.new(1002) }
  248. heli_r_part = create{ "Part", TopSurface = 0, BottomSurface = 0, FormFactor = "Custom", Parent = heli_model, CanCollide = false, Size = Vector3.new(0.2, 1, 0.2), BrickColor = BrickColor.new(1002) }
  249. heli_l_axel = create{ "Part", TopSurface = 0, BottomSurface = 0, FormFactor = "Custom", Parent = heli_model, CanCollide = false, Size = Vector3.new(0.2, 0.7, 0.2), BrickColor = BrickColor.new(1002) }
  250. heli_r_axel = create{ "Part", TopSurface = 0, BottomSurface = 0, FormFactor = "Custom", Parent = heli_model, CanCollide = false, Size = Vector3.new(0.2, 0.7, 0.2), BrickColor = BrickColor.new(1002) }
  251. heli_l_top = create{ "Part", TopSurface = 0, BottomSurface = 0, FormFactor = "Custom", Parent = heli_model, CanCollide = false, Size = Vector3.new(0.3, 0.2, 0.3), BrickColor = BrickColor.new("Black") }
  252. heli_r_top = create{ "Part", TopSurface = 0, BottomSurface = 0, FormFactor = "Custom", Parent = heli_model, CanCollide = false, Size = Vector3.new(0.3, 0.2, 0.3), BrickColor = BrickColor.new("Black") }
  253. create{"CylinderMesh", Parent = heli_l_top, Scale = Vector3.new(1,0.4,1) }
  254. create{"CylinderMesh", Parent = heli_r_top, Scale = Vector3.new(1,0.4,1) }
  255. create{"CylinderMesh", Parent = heli_l_part }
  256. create{"CylinderMesh", Parent = heli_r_part }
  257. create{"CylinderMesh", Parent = heli_l_axel, Scale = Vector3.new(0.8,1,0.8) }
  258. create{"CylinderMesh", Parent = heli_r_axel, Scale = Vector3.new(0.8,1,0.8) }
  259.  
  260. create{ "Weld", Part0 = heli_motor, Part1 = heli_l_part, C0 = CFrame.new( -0.9, 0.65, 0 ) * CFrame.Angles(0,math.pi/2,0) * CFrame.Angles(-math.pi/2,0,0), C1 = CFrame.new(0, -0.5, 0), Parent = heli_model }
  261. create{ "Weld", Part0 = heli_motor, Part1 = heli_r_part, C0 = CFrame.new( 0.9, 0.65, 0 ) * CFrame.Angles(0,-math.pi/2,0) * CFrame.Angles(-math.pi/2,0,0), C1 = CFrame.new(0, -0.5, 0), Parent = heli_model }
  262. create{ "Weld", Part0 = heli_l_part, Part1 = heli_l_axel, C0 = CFrame.new( 0, 0.38, 0 ) * CFrame.Angles(0, 0, 1.4), C1 = CFrame.new(0, -0.3, 0), Parent = heli_model }
  263. create{ "Weld", Part0 = heli_r_part, Part1 = heli_r_axel, C0 = CFrame.new( 0, 0.38, 0 ) * CFrame.Angles(0, 0, -1.4), C1 = CFrame.new(0, -0.3, 0), Parent = heli_model }
  264.  
  265. heli_l_weld = create{ "Weld", Part0 = heli_l_axel, Part1 = heli_l_top, C0 = CFrame.new( 0, 0.4, 0 ), Parent = heli_model }
  266. heli_r_weld = create{ "Weld", Part0 = heli_r_axel, Part1 = heli_r_top, C0 = CFrame.new( 0, 0.4, 0 ), Parent = heli_model }
  267.  
  268. for angle = 0, 360-90, 90 do
  269. local part = clone_rotor:clone()
  270. part.Size = Vector3.new(0.6,0.2,1.6)
  271. create{ "BlockMesh", Parent = part, Scale = Vector3.new(1,0,1) }
  272. create{ "Weld", Part0 = heli_l_top, Part1 = part, C0 = CFrame.Angles(0, math.rad(angle), 0), C1 = CFrame.new( 0, 0, -0.8 ), Parent = heli_model }
  273. part.Parent = heli_model
  274. local part2 = clone_rotor:clone()
  275. part2.Size = Vector3.new(0.6,0.2,1.6)
  276. create{ "BlockMesh", Parent = part2, Scale = Vector3.new(1,0,1) }
  277. create{ "Weld", Part0 = heli_r_top, Part1 = part2, C0 = CFrame.Angles(0, math.rad(angle), 0), C1 = CFrame.new( 0, 0, -0.8 ), Parent = heli_model }
  278. part2.Parent = heli_model
  279. end
  280.  
  281. heli_sound.Parent = heli_axeltop
  282. bodyforce = create{ "BodyForce", force = Vector3.new(), Parent = heli_top }
  283. bodygyro = create{ "BodyGyro", maxTorque = Vector3.new( 3000, 3000, 3000 ), P = 65, D = 7 }
  284.  
  285.  
  286. heli_rotorspeed = 0
  287. heli_rotorrot = 0
  288. heli_throttle = 0
  289. heli_targetthrottle = 0
  290.  
  291. heli_sound:Play()
  292.  
  293. updateMass()
  294. closePack()
  295.  
  296. character.DescendantAdded:connect( updateMass )
  297. character.DescendantRemoving:connect( updateMass )
  298.  
  299. local prevTime = tick()
  300.  
  301. local a = 0
  302.  
  303. loop = function()
  304. local currTime = tick()
  305. local delta = currTime - prevTime
  306. prevTime = currTime
  307.  
  308. handleInput()
  309.  
  310. if collision_time > 0 then
  311. collision_time = collision_time - delta
  312. else
  313. if pack_open and bodygyro.Parent ~= heli_top then
  314. bodygyro.Parent = heli_top
  315. end
  316. end
  317.  
  318. heli_throttle = heli_throttle + (heli_targetthrottle - heli_throttle)*(0.06*delta*60.0)
  319. heli_rotorspeed = heli_throttle*3200
  320. heli_sound.Pitch = 1.9 + ( heli_throttle - 1 )*1
  321.  
  322. if heli_throttle > 0.002 then
  323. if heli_sound.IsPaused then
  324. heli_sound:Play()
  325. end
  326. heli_sound.Volume = 0.28*(heli_throttle-0.002)
  327. else
  328. if heli_sound.IsPlaying then
  329. heli_sound:Pause()
  330. end
  331. end
  332.  
  333. heli_rotorrot = heli_rotorrot + heli_rotorspeed*delta
  334. if heli_rotorrot > 180 then heli_rotorrot = heli_rotorrot - 360 elseif heli_rotorrot < -180 then heli_rotorrot = heli_rotorrot + 360 end
  335. heli_rotor_weld.C0 = CFrame.new(0, 1.6, 0) * CFrame.Angles( 0, math.rad(-heli_rotorrot), 0 )
  336. heli_l_weld.C1 = CFrame.Angles( 0, math.rad(heli_rotorrot), 0 )
  337. heli_r_weld.C1 = CFrame.Angles( 0, math.rad(heli_rotorrot), 0 )
  338.  
  339. local cf = camera.CoordinateFrame * CFrame.Angles( math.rad(15), 0, 0 ) * tilt
  340. bodygyro.cframe = cf
  341. local up = ( torso.CFrame * CFrame.Angles( math.pi/2, 0, 0 )).lookVector
  342.  
  343. local acc = Vector3.new(1,1,1)*196.2*heli_throttle
  344. bodyforce.force = up * acc * bodymass
  345.  
  346. local hit, hitpos = workspace:FindPartOnRay( Ray.new( torso.CFrame.p, -up*3.1 ), character )
  347.  
  348. if hit and pack_open and up.y > 0.88 and bodygyro.Parent == heli_top then
  349. if hit.CanCollide then
  350. closePack()
  351. end
  352. end
  353.  
  354. for i, _ in pairs( framekeys ) do
  355. framekeys[i] = false
  356. end
  357. end
  358.  
  359. oc = oc or function(f) return f end
  360.  
  361. game:service("RunService").RenderStepped:connect( oc(loop) )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement