- Home /
Particle systems: Defining the vertices of an EDGE-type emitter
Hey,
I was wondering if its possible to emit particles along an edge that has its vertices defined programattically.
For example, on click, instantiate a particle emitter with shape-type EDGE that has vertices at (0,0,0) and (1,1,2). In another case I want it to have vertices at (1,1.5,3), and (2,5,2)... etc. These are just arbitrary numbers. I want to be able to define the 'mesh' with each click.
I tried making a mesh with just two vertices but I got lost half way because I don't know how to save a mesh prefab to be dragged into the 'mesh' box in the editor.
Answer by FortisVenaliter · Sep 07, 2017 at 08:05 PM
Personally, I would do this programmatically. You can call the Particle System's Emit() function with a position specified, so... handle the emission yourself. Calculate a random point on the line and emit a particle there each frame, or more if you want. That way you don't need to add a mesh or anything complicated.
I assume you're talking about modifying this?:
https://docs.unity3d.com/ScriptReference/ParticleSystem.EmitParams-position.html
In this case, if the line happened to be long and I wanted a particle emitted every inch or so, I'd have to instantiate 50 gameobject each emitting one particle... this doesn't seem feasible. Surely there must be a way to emit particle along a line? For example.. define two points that constitute the mesh and emit along it. No?
Not at all. You only need to create one. You just need to modify the position on it in between emitting each particle, and you can keep passing in the same instance.
Plus, EmitParams is a struct, not a GameObject. Very different in how memory is handled.
So in my case, I instantiate a prefab particle emitter gameobject and move the transform of that gameobject? I want all of the particles to appear simultaneously along that line, not one by one. Seems like doing it this way, it would emit a single particle each frame and I'd have to specify the new position of it in every Update() call.
Forgive me if I'm wrong again but I think you need to include more detail in what you're saying. Basically what I'm making is a lazer. The player shoots from the tip of the gun to a point on the map. I want, after the lazer has been shot (which is currently handled with a lineRenderer), particles to spawn and decay as though the heat of the lazer warped the path that was shot. I don't want a single particle emitted every frame along the path.
Answer by richardkettlewell · Sep 08, 2017 at 09:34 PM
We've just added support for particle systems to Emit from meshes that use the Lines primitive type, in 2017.3.
Just create a mesh, similar to here: https://docs.unity3d.com/ScriptReference/Mesh.html
And then assign it to the shape module of your particle system.
(I'm posting this mainly as a hint for future readers, as 2017.3 is not yet out, as I write this!)
Your answer
Follow this Question
Related Questions
moving hole 3 Answers
Creating 3D shapes by given coordinates 0 Answers
May I substitue the default particles with my particular mesh? 2 Answers
Finding the height of a mesh 1 Answer