- Home /
Change Particle Emitter fire rate?
I swear there was a setting in the emitter to change the rate/speed of the particle going off or something like that.
Thats basically what I want to do. Also I wanted to randomize the rate/speed using a min and max value.
I could achieve both easily with scripting but was wondering if there was a proper way to do it?
The only script ideas I've got is to either:
- enable/disable the emitter on a timer.
- instantiate a particle emitter and then have it destroy itself
Is either the correct way to script it? (Obviously we would want the most efficient way)
Is there a more convenient way to do this?
Edit: I'm using, and need to use one-shot.
Answer by Rabwin · Apr 12, 2011 at 12:27 AM
I ended up answering my own question after some searching through the scripting reference on the emitter. Thanks for trying to help through. Is it just me or is there a lot of people who are suddenly able to answer their own questions almost right after asking them.
Well, heres a basic script I came up with to achieve the effect I wanted.
using UnityEngine; using System.Collections;
public class ParticleEmitter_FireRate : MonoBehaviour { public float fireRate = 1.0f; // The rate at which particles should be Emitted. public bool randomizeFireRate = true; public float randomNum = 1.0f; private float lastTime; private float newRate; public int minParticles = 0, maxParticles = 5; void Awake() { if (particleEmitter.emit == true) { particleEmitter.emit = false; } lastTime = Time.time; newRate = fireRate; }
void Update()
{
if (Time.time > lastTime + newRate)
{
particleEmitter.Emit (Random.Range(minParticles, maxParticles));
lastTime = Time.time;
if (randomizeFireRate == true)
{
newRate = Random.Range(fireRate - randomNum, fireRate + randomNum);
}
}
}
}
Edit: Plus it's much much easier to use than playing around with the velocity/energy. Also as you can see, I use my own timers instead of the unity built ones. I just never liked them.
Answer by DaveA · Apr 11, 2011 at 03:35 PM
Look at Rnd Velocity (for direction/speed of movement), and Min and Max Emmission for rates
Are you sure that's what it is? The Rnd Velocity I'm looking at contains a vector3 which affects the DIRECTION of the particles, but not the rate at which particles are actually created. I should probably add, that I am using one-shot and need to use it.
Sorry that would be $$anonymous$$in and $$anonymous$$ax Emmission
I'm confused, for me $$anonymous$$ and max emission just changes the amount of particles co$$anonymous$$g out, but it's still firing at the same speed.
Also, if you have a look at Energy, it does a similar thing where it makes the shot particles last longer, and end result is the next shot of particles are delayed until the current ones die.
I just don't want the particles to fly that far.
If the emission numbers are set higher, it has to produce more particles. Energy does indeed play a part in that the longer particles last, the sooner the emission 'maxes out'. I suppose you could come up with a formula that converts Unity's numbers into 'particles per second'. Sounds like you want a high $$anonymous$$ emission and low energy. Velocity will deter$$anonymous$$e how far they fly in that short time.
Your answer
Follow this Question
Related Questions
Using Particles with Collision 2 Answers
particleSystem.Play(); wont start 1 Answer
Is there a way to draw particles on a raycast? 2 Answers