Advertisement
CupNoodle3706

Plane Script #2

May 1st, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.90 KB | None | 0 0
  1. local player = game:service("Players").LocalPlayer
  2. local mouse = player:GetMouse()
  3. local cam = workspace.CurrentCamera
  4. local char = player.Character
  5. local Torsoz = char:findFirstChild("Torso")
  6. local NV = Vector3.new()
  7. local Main
  8. local W,S = false,false
  9. local DoublePress = {nil,0}
  10. script.Parent = char
  11.  
  12. local TrailParts = {}
  13. local Acceleration = 0.08
  14. local Speed = 0
  15. local MinSpeed = 0
  16. local MaxSpeed = 3.2
  17. local DesiredDirection = cam.CoordinateFrame.lookVector
  18. local Direction = DesiredDirection
  19. local Roll = 0
  20. local AllowTrails = true
  21.  
  22. script.Name = "AdvFlight"
  23.  
  24. local P = Instance.new("Part")
  25. P.Anchored = true
  26. P.CanCollide = false
  27. P.Name = "Part"
  28. P.formFactor = "Custom"
  29. P.Size = Vector3.new(0.2,0.2,0.2)
  30. P.Locked = true
  31. P.TopSurface = 10
  32. P.BottomSurface = 10
  33. P.FrontSurface = 10
  34. P.BackSurface = 10
  35. P.LeftSurface = 10
  36. P.RightSurface = 10
  37. P.Material = "Pebble"
  38. P.BrickColor = BrickColor.new("White")
  39.  
  40. local shipp
  41. local shadow
  42. local campart
  43.  
  44. function RAY(pos, dir, startpos, endpos, distleft, collidedlist)
  45. collidedlist = collidedlist or {char}
  46. startpos = startpos or pos
  47. distleft = distleft or dir.unit * dir.magnitude
  48. endpos = endpos or pos + distleft
  49. local ray = Ray.new(pos, distleft)
  50. local hitz,enz = workspace:FindPartOnRayWithIgnoreList(ray, collidedlist)
  51. if hitz ~= nil then
  52. if hitz.CanCollide == false then
  53. table.insert(collidedlist, hitz)
  54. local newpos = enz
  55. local newdistleft = distleft - (dir.unit * (pos - newpos).magnitude)
  56. if newdistleft ~= NV then
  57. return RAY(newpos-(dir*0.01), dir, startpos, endpos, newdistleft+(dir*0.01), collidedlist)
  58. end
  59. end
  60. end
  61. return hitz, enz, ray
  62. end
  63.  
  64. function FindSurface(part, position)
  65. local obj = part.CFrame:pointToObjectSpace(position)
  66. local siz = part.Size/2
  67. for i,v in pairs(Enum.NormalId:GetEnumItems()) do
  68. local vec = Vector3.FromNormalId(v)
  69. local wvec = part.CFrame:vectorToWorldSpace(vec)
  70. local vz = (obj)/(siz*vec)
  71. if (math.abs(vz.X-1) < 0.01 or math.abs(vz.Y-1) < 0.01 or math.abs(vz.Z-1) < 0.01) then
  72. return wvec,vec
  73. end
  74. end
  75. if part.className == "WedgePart" then
  76. return part.CFrame:vectorToWorldSpace(Vector3.new(0,0.707,-0.707)), Vector3.new(0,0.707,-0.707)
  77. end
  78. end
  79.  
  80. function HSV(H,S,V)
  81. H = H % 360
  82. local C = V * S
  83. local H2 = H/60
  84. local X = C * (1 - math.abs((H2 %2) -1))
  85. local color = Color3.new(0,0,0)
  86. if H2 <= 0 then
  87. color = Color3.new(C,0,0)
  88. elseif 0 <= H2 and H2 <= 1 then
  89. color = Color3.new(C,X,0)
  90. elseif 1 <= H2 and H2 <= 2 then
  91. color = Color3.new(X,C,0)
  92. elseif 2 <= H2 and H2 <= 3 then
  93. color = Color3.new(0,C,X)
  94. elseif 3 <= H2 and H2 <= 4 then
  95. color = Color3.new(0,X,C)
  96. elseif 4 <= H2 and H2 <= 5 then
  97. color = Color3.new(X,0,C)
  98. elseif 5 <= H2 and H2 <= 6 then
  99. color = Color3.new(C,0,X)
  100. end
  101. local m = V - C
  102. return Color3.new(color.r + m, color.g + m, color.b + m)
  103. end
  104.  
  105. function Build(shiptype)
  106. AllowTrails = true
  107. for i, v in pairs(char:children()) do
  108. if v.className == "Model" and v.Name == "Ship" then
  109. v:remove()
  110. end
  111. end
  112. for i, v in pairs(TrailParts) do
  113. for _,V in pairs(v[3]) do
  114. V:Destroy()
  115. end
  116. end
  117. local mdl = Instance.new("Model", char)
  118. mdl.Name = "Ship"
  119.  
  120. ------------------------ Speeder Ship Type -----------------------------
  121. if shiptype == "Speeder" then
  122.  
  123. shipp = P:Clone()
  124. shipp.Parent = mdl
  125. shipp.Size = Vector3.new(1,1,2.2)
  126. local shipwing1 = P:Clone()
  127. shipwing1.Parent = mdl
  128. shipwing1.Size = Vector3.new(0.6,1.2,2)
  129. local mesh = Instance.new("SpecialMesh", shipwing1)
  130. mesh.MeshType = "Wedge"
  131. local shipwing2 = shipwing1:Clone()
  132. shipwing2.Parent = mdl
  133. campart = P:Clone()
  134. campart.Transparency = 1
  135. local shipwing21 = P:Clone()
  136. shipwing21.Parent = mdl
  137. shipwing21.Size = Vector3.new(0.32,1.1,2.6)
  138. local mesh = Instance.new("SpecialMesh", shipwing21)
  139. mesh.MeshType = "Wedge"
  140. local shipwing22 = shipwing21:Clone()
  141. shipwing22.Parent = mdl
  142. campart = P:Clone()
  143. campart.Transparency = 1
  144.  
  145. local shipwi = P:Clone()
  146. shipwi.Parent = mdl
  147. shipwi.Size = Vector3.new(1,1,1.2)
  148. local mesh = Instance.new("SpecialMesh", shipwi)
  149. mesh.MeshType = "Wedge"
  150. local shipwi2 = P:Clone()
  151. shipwi2.Parent = mdl
  152. shipwi2.Size = Vector3.new(0.7,0.7,0.84)
  153. shipwi2.Material = "SmoothPlastic"
  154. shipwi2.BrickColor = BrickColor.new("Pastel blue")
  155. shipwi2.Reflectance = 0.6
  156. local mesh = Instance.new("SpecialMesh", shipwi2)
  157. mesh.MeshType = "Wedge"
  158.  
  159. shadow = P:Clone()
  160. shadow.Parent = mdl
  161. shadow.Name = "Shadow"
  162. shadow.Material = "SmoothPlastic"
  163. shadow.BrickColor = BrickColor.new("Really black")
  164. local mesh = Instance.new("SpecialMesh",shadow)
  165. mesh.MeshType = "Sphere"
  166.  
  167. TrailParts = {}
  168. table.insert(TrailParts,{shipp,1,{},cam.CoordinateFrame.p,CFrame.new(0,0,1),0.5,18})
  169. table.insert(TrailParts,{shipwing1,1,{},cam.CoordinateFrame.p,CFrame.new(0,0.45,1),0.3,15})
  170. table.insert(TrailParts,{shipwing2,1,{},cam.CoordinateFrame.p,CFrame.new(0,0.45,1),0.3,15})
  171. for _, V in pairs(TrailParts) do
  172. for i = 1, V[7] do
  173. local p = P:Clone()
  174. local mesh = Instance.new("SpecialMesh", p)
  175. mesh.MeshId = "http://www.roblox.com/asset/?id=9856898"
  176. mesh.TextureId = "http://www.roblox.com/asset/?id=48358980"
  177. p.BrickColor = BrickColor.new("Dark stone grey")
  178. table.insert(V[3],p)
  179. end
  180. end
  181.  
  182. function ReposParts()
  183. shipwing1.CFrame = shipp.CFrame * CFrame.new(-1.1,-0.195,-0.14) * CFrame.Angles(0,0,math.pi/2)
  184. shipwing2.CFrame = shipp.CFrame * CFrame.new(1.1,-0.195,-0.14) * CFrame.Angles(0,0,-math.pi/2)
  185. shipwing21.CFrame = shipp.CFrame * CFrame.new(-1.05,-0.34,-0.45) * CFrame.Angles(0,0,math.pi/2)
  186. shipwing22.CFrame = shipp.CFrame * CFrame.new(1.05,-0.34,-0.45) * CFrame.Angles(0,0,-math.pi/2)
  187. shipwi.CFrame = shipp.CFrame * CFrame.new(0,0,-1.7)
  188. shipwi2.CFrame = shipwi.CFrame * CFrame.new(0,0.015,-0.015)
  189. campart.CFrame = shipp.CFrame + Vector3.new(0,1.5,0)
  190. end
  191. cam.CameraSubject = campart
  192. cam.CameraType = "Track"
  193.  
  194. shipp.CFrame = CFrame.new(NV,Direction) + cam.CoordinateFrame.p
  195. ReposParts()
  196.  
  197. end
  198.  
  199. AllowTrails = true
  200. end
  201. Build("Speeder")
  202.  
  203. function B1D()
  204. Build("Speeder")
  205. end
  206.  
  207. function RollThatSht(direc)
  208. if Roll == 0 then
  209. for i = 1, 50 do
  210. Roll = (-360 + math.cos(math.pi/50*i) * 360) * direc
  211. wait(0.02)
  212. end
  213. Roll = 0
  214. end
  215. end
  216.  
  217. function KD(key)
  218. if key == "w" then
  219. W = true
  220. elseif key == "s" then
  221. S = true
  222. end
  223.  
  224. local rollpls = 0
  225. if key == DoublePress[1] and tick() - DoublePress[2] < 0.32 then
  226. DoublePress = {nil,0}
  227. if key == "a" then
  228. rollpls = -1
  229. elseif key == "d" then
  230. rollpls = 1
  231. end
  232. end
  233.  
  234. DoublePress = {key,tick()}
  235. if rollpls ~= 0 then
  236. RollThatSht(rollpls)
  237. end
  238. end
  239.  
  240. function KU(key)
  241. if key == "w" then
  242. W = false
  243. elseif key == "s" then
  244. S = false
  245. end
  246. end
  247.  
  248. function Equip()
  249. end
  250.  
  251. function Unequip()
  252. end
  253.  
  254. mouse.Icon = "rbxasset://textures\\GunCursor.png"
  255. mouse.Button1Down:connect(B1D)
  256. mouse.KeyDown:connect(KD)
  257. mouse.KeyUp:connect(KU)
  258.  
  259.  
  260.  
  261. local count = 0
  262. local hue = 0
  263. --game:GetService("RunService").Stepped:connect(function()
  264. while wait(0.02) do
  265.  
  266. ------ Speed --------
  267. local valu = (0.002*MaxSpeed) + ((Speed/MaxSpeed)*Acceleration)
  268. if W == true then
  269. Speed = Speed + valu
  270. elseif S == true then
  271. Speed = Speed - valu
  272. end
  273. if Speed > MaxSpeed then
  274. Speed = MaxSpeed
  275. elseif Speed < MinSpeed then
  276. Speed = MinSpeed
  277. end
  278.  
  279. ------ left/right tilt ---------
  280. local target = 180 + math.floor(math.deg(math.atan2(DesiredDirection.x,DesiredDirection.z)))
  281. local current = 180 + math.floor(math.deg(math.atan2(Direction.x,Direction.z)))
  282. local swing = 0
  283. if math.abs(math.abs(current-target) - 360) > math.abs(target-current) then
  284. swing = target-current
  285. else
  286. swing = (current > target and -(math.abs(current-target) - 360)) or (current < target and math.abs(current-target) - 360)
  287. end
  288.  
  289. DesiredDirection = cam.CoordinateFrame.lookVector
  290. ------ direction smoothening ------
  291. local dir = DesiredDirection.unit
  292. if Direction ~= dir then
  293. if (Direction - dir).magnitude < 0.01 then
  294. Direction = dir
  295. else
  296. local dist = ((dir - Direction).unit * (dir - Direction).magnitude) /10
  297. Direction = (Direction + dist).unit
  298. end
  299. end
  300.  
  301. shipp.CFrame = (CFrame.new(NV,Direction) + shipp.Position + (Direction.unit * Speed)) * CFrame.Angles(0,0,math.rad(Roll) + math.rad(swing/2))
  302. ReposParts()
  303.  
  304. ------ shadow ------
  305. local ghitz, genz = RAY(shipp.Position,Vector3.new(0,-26,0))
  306. local angles = CFrame.new()
  307. if ghitz ~= nil and ghitz.className ~= "Terrain" and ((ghitz.className == "Part" and ghitz.Shape == Enum.PartType.Block) or (ghitz.className ~= "Part" and ghitz:IsA("BasePart"))) then
  308. local wvec,vec = FindSurface(ghitz,genz)
  309. angles = CFrame.new(NV,wvec) * CFrame.Angles(-math.pi/2,0,0)
  310. elseif ghitz ~= nil and (ghitz.className == "Part" and ghitz.Shape == Enum.PartType.Ball) then
  311. angles = (CFrame.new(ghitz.Position, genz) - ghitz.Position) * CFrame.Angles(-math.pi/2,0,0)
  312. end
  313. shadow.CFrame = CFrame.new(genz) * angles
  314. shadow.Transparency = 0.5 + (((shipp.Position - genz).magnitude /26)*0.5)
  315. shadow.Mesh.Scale = (Vector3.new(4.4,0.25,4.4) * 5) * (1-(shipp.Position - genz).magnitude /26)
  316.  
  317. ------- Trails -----------------------
  318. if AllowTrails == true then
  319. count = (count+1)%1
  320. hue = (hue+1) % 360
  321. local rgb = HSV(hue,0.65,0.85)
  322. for _,v in pairs(TrailParts) do
  323. local to = (v[1].CFrame * v[5]).p
  324. if Speed > MinSpeed + 0.2 then
  325. v[2] = (v[2]%#v[3]) + 1
  326. v[3][v[2]].CFrame = CFrame.new((v[4] + to)/2,to) * CFrame.Angles(math.pi/2,math.rad(Roll) + math.rad(swing/2),0)
  327. v[3][v[2]].Mesh.Scale = Vector3.new(v[6],(v[4] - to).magnitude*2,v[6])
  328. v[3][v[2]].Mesh.VertexColor = Vector3.new(rgb.r,rgb.g,rgb.b)
  329. v[3][v[2]].Transparency = 0.15
  330. v[3][v[2]].Parent = game.Players.LocalPlayer.Character
  331. else
  332. v[2] = (v[2]%#v[3]) + 1
  333. v[3][v[2]].Parent = nil
  334. end
  335.  
  336. v[4] = to
  337. end
  338. end
  339.  
  340. end
  341. --end)
  342.  
  343. -- 138098590 -- plane destroyed sound
  344. -- 133082569 -- propeller 2
  345. -- 135645246 -- propeller 1
  346. --[[ Possible Game names
  347. Aeroscape
  348. Airbound
  349. Aerialtude
  350. ]]
  351. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement