Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.62 KB | None | 0 0
  1. local runservice = game:GetService("RunService")
  2. local rad = math.rad
  3. local twserv = game:GetService("TweenService")
  4.  
  5. local m = {}
  6.  
  7. m.CreateParticles = function(info)
  8.     --if true then
  9.        
  10.        
  11.         local castedparts = {}
  12.        
  13.        
  14.        
  15.         for i = 1, info["amount" or 1] do
  16.            
  17.             local randomising = info["random"] or tick()
  18.             local prt = Instance.new("Part")
  19.             local ignore = {unpack(info["ignore"]or{}), prt, workspace.Effects}
  20.             prt.Color = info["color"] or Color3.new(1,1,1)
  21.             prt.Material = info["material"] or Enum.Material.Neon
  22.             if prt.Material == Enum.Material.Neon then
  23.                 local l = Instance.new("SurfaceLight")
  24.                 l.Color = prt.Color
  25.                 l.Angle = 180
  26.                 l.Brightness = 1
  27.                 l.Range = 6
  28.                 l.Shadows = true
  29.                 l.Face = "Front"
  30.                 l.Parent = prt
  31.             end
  32.             prt.Size = Vector3.new(1,1,1)
  33.             local premesh = Instance.new("SpecialMesh")
  34.             premesh.MeshType = Enum.MeshType.Cylinder
  35.             premesh.Parent = prt
  36.             prt.Transparency = info["transparency"] or 0
  37.             prt.CanCollide = false
  38.             prt.Anchored = true
  39.             --prt.Shape = info["shape"] or Enum.PartType.Cylinder
  40.             table.insert(ignore, prt)
  41.             table.insert(castedparts, prt)
  42.            
  43.             if info.transperencyfadeout then
  44.                 local twi = {}
  45.                 twi.Transparency = 1
  46.                 local twinfo = TweenInfo.new(.98, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, .3)
  47.                 local tween = twserv:Create(prt, twinfo, twi)
  48.                 tween:Play()
  49.             end
  50.            
  51.             prt.Parent = info["parent"] or workspace
  52.            
  53.             spawn(function()
  54.                
  55.                 game.Debris:AddItem(prt, info["maxtime"] or 2)
  56.                 local doing = true
  57.                 delay(info["maxtime"]or 2, function()
  58.                     doing = false
  59.                 end)
  60.                 local bounces = 0
  61.                 --local startpos = info["start"]
  62.    
  63.                 local lastpos = info["start"].p
  64.                 local lasttime = tick()
  65.                 local spread = info["spread"]*100
  66.                
  67.                 local randomangles = Vector3.new(rad(math.random(-spread, spread)/100), rad(math.random(-spread, spread)/100), rad(math.random(-spread, spread)/100))
  68.                 local randomvel = math.random(info["velspread"][1]*100, info["velspread"][2]*100)/100
  69.                 local vel = (info["start"] * CFrame.Angles(randomangles.X, randomangles.Y, randomangles.Z)).lookVector*randomvel*info["vel"]
  70.                 while doing and ( bounces < (info["bounces"] or 3) ) and prt.Transparency <1 do
  71.                     runservice.Heartbeat:Wait()
  72.                     local dt = tick() - lasttime
  73.                     local mnusy = ( workspace.Gravity*dt*(info["gravitycounter"] or 1))
  74.                    
  75.                     vel = Vector3.new(vel.X, vel.Y-mnusy, vel.Z)
  76.                    
  77.                     vel = vel*(info.drag or .965)
  78.                     --print(vel.Y)
  79.                     local newpos = lastpos + vel*dt
  80.                     local d = (lastpos - newpos).magnitude
  81.                     --print(lastpos)
  82.                     local cf = CFrame.new(lastpos, newpos)
  83.                     local r = Ray.new(cf.p, cf.LookVector*(d))
  84.                     local obj, pos, normal, mat = workspace:FindPartOnRayWithIgnoreList(r, {unpack(ignore), unpack(castedparts), workspace.Effects})
  85.                     --print(obj)
  86.                     if obj then
  87.                         --print(obj:GetFullName())
  88.                         bounces = bounces +1
  89.                         local casted = (cf.LookVector - ( 2 * cf.LookVector:Dot(normal) * normal))
  90.                        
  91.                         local castedvel = vel.magnitude
  92.                         --print(1-bounces/info["bounces"])
  93.                         vel = CFrame.new(pos, pos+casted).lookVector *castedvel*(1-bounces/info["bounces"])
  94.                        
  95.                     end
  96.                    
  97.                     prt.CFrame = cf * CFrame.new(0, 0, -d/2) * CFrame.Angles(0, math.pi/2, 0)
  98.                    
  99.                     premesh.Scale = Vector3.new(d+info["size"].Z, info["size"].Y, info["size"].X)
  100.                    
  101.                     lastpos = newpos
  102.                     lasttime = tick()
  103.                 end
  104.                 if prt then
  105.                     prt:Destroy()
  106.                 end
  107.                 coroutine.yield()
  108.             end)
  109.         end
  110.        
  111.         --print("gae")
  112.         return castedparts
  113.     --else
  114.         --return {}
  115.     --end
  116. end
  117.  
  118.  
  119. return m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement