Ozzypig

Creating a ParticleEmitter from Scratch

May 27th, 2018
251
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local emitter = Instance.new("ParticleEmitter")
  2. -- Number of particles = Rate * Lifetime
  3. emitter.Rate = 5 -- Particles per second
  4. emitter.Lifetime = NumberRange.new(1,1) -- How long the particles should be alive (min, max)
  5. emitter.Enabled = true
  6.  
  7. -- Visual properties
  8. emitter.Texture = "rbxassetid://1266170131" -- A transparent image of a white ring
  9. -- For Color, build a ColorSequence using ColorSequenceKeypoint
  10. local colorKeypoints = {
  11.     -- API: ColorSequenceKeypoint.new(time, color)
  12.     ColorSequenceKeypoint.new( 0, Color3.new(1, 1, 1)),  -- At t=0, White
  13.     ColorSequenceKeypoint.new(.5, Color3.new(1, .5, 0)), -- At t=.5, Orange
  14.     ColorSequenceKeypoint.new( 1, Color3.new(1, 0, 0))   -- At t=1, Red
  15. }
  16. emitter.Color = ColorSequence.new(colorKeypoints)
  17. local numberKeypoints = {
  18.     -- API: NumberSequenceKeypoint.new(time, size, envelop)
  19.     NumberSequenceKeypoint.new( 0, 1);    -- At t=0, fully transparent
  20.     NumberSequenceKeypoint.new(.1, 0);    -- At t=.1, fully opaque
  21.     NumberSequenceKeypoint.new(.5, .25);  -- At t=.5, mostly opaque
  22.     NumberSequenceKeypoint.new( 1, 1);    -- At t=1, fully transparent
  23. }
  24. emitter.Transparency = NumberSequence.new(numberKeypoints)
  25. emitter.LightEmission = 1 -- When particles overlap, multiply their color to be brighter
  26. emitter.LightInfluence = 0 -- Don't be affected by world lighting
  27.  
  28. -- Speed properties
  29. emitter.EmissionDirection = Enum.NormalId.Front -- Emit forwards
  30. emitter.Speed = NumberRange.new(0, 0) -- Speed of zero
  31. emitter.Drag = 0 -- Apply no drag to particle motion
  32. emitter.VelocitySpread = NumberRange.new(0, 0)
  33. emitter.VelocityInheritance = 0 -- Don't inherit parent velocity
  34. emitter.Acceleration = Vector3.new(0, 0, 0)
  35. emitter.LockedToPart = false -- Don't lock the particles to the parent
  36. emitter.SpreadAngle = Vector2.new(0,0) -- No spread angle on either axis
  37.  
  38. -- Simulation properties
  39. local numberKeypoints2 = {
  40.     NumberSequenceKeypoint.new(0, 0);  -- At t=0, size of 0
  41.     NumberSequenceKeypoint.new(1, 10); -- At t=1, size of 10
  42. }
  43. emitter.Size = NumberSequence.new(numberKeypoints2)
  44. emitter.ZOffset = -1 -- Render slightly behind the actual position
  45. emitter.Rotation = NumberRange.new(0, 360) -- Start at random rotation
  46. emitter.RotSpeed = NumberRange.new(0) -- Do not rotate during simulation
  47.  
  48. -- Create an attachment
  49. local attachment = Instance.new("Attachment", script.Parent)
  50. attachment.Position = Vector3.new(0, 5, 0) -- Move the attachment upwards a little
  51. emitter.Parent = attachment
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×