- Home /
Smoothly start and stop particles
Basic issue:
I have a bunch of particles frozen in space by setting particleEmitter = false;
When re-enabling the particleEmitter ("un-pausing the particles"), I want them to gradually accelerate to their original speed and continue on course.
Current setup:
I am using a legacy Mesh Particle Emitter to emit particles inward from a sphere mesh.
The particles look like stars, and the effect I am achieving:
Emit particles for several seconds to fill the screen with particles that look like stars.
Set
particleEmitter.enabled = false;
This freezes the star particles in space, and it looks like a typical photograph of a starry sky.Now, I want to simulate a camera "zoom out" through the stars. To achieve this, I set
Time.timeScale = 0f; particleEmitter.enable = true;
In the Update() function,
Time.timeScale += .001f;
to gradually raise back to Time.timeScale = 1.0f. This effectively makes it look like the particles gradually accelerate back to their original velocity.
This setup works pretty well, EXCEPT for a problem occurs in Step 3: Its seems like after re-enabling the particleEmitter, even though Time.timeScale is set to zero, the particles retain their original speed for a single frame, causing a notable jump in the particle animation.
tl;dr
Even if Time.timeScale remains set to zero, re-enabling the particleEmitter on a legacy Mesh Particle Emitter allows particles to retain original velocity or movement amount for a single frame, which causes a jump in motion.
Is there some workaround, like setting each particle's velocity to 0 and then increasing it again?
Answer by MarkD · Oct 09, 2013 at 08:26 PM
I think you need to create a for loop accessing all particles and their speed value. Because if you freeze time, you don't remove their current velocity value, it will be the same and can only be changed in the next frame.
So what's happening is when you speed up your time again, the particle system will already have calculated the current velocity and thus the distance and location for the next frame coming. That is what is causing your stutter.
Thanks, this works perfectly! I'm fiddling around with a few different implementations.
I figured that the solution would be something like this, but I wasn't sure how to interact with individual particles in a practical way. Thanks for the advice.
Hm, I'm actually having inconsistent results when reassigning a velocity to the previously-frozen particles. It seems to work at random times, and at other times causes the same jump.
I will experiment by perfor$$anonymous$$g some actions in FixedUpdate or LateUpdate, but in the meantime, it's actually okay to just keep the old particles with a velocity of (0,0,0), and to let them just fade out in place.
Well, since you need to do the calculations before the next frame LastUpdate could maybe work, because this will cause to do the calculations after the frame is drawn and apply them to the next, so if you stop time at that current stopped frame your calculation will be done and ready for the next frame, so basically you have override the particle systems calculation. But as always with particle systems it is a lot of fiddling around as you said.
Thanks for the extra insight, $$anonymous$$arkD. I am still fiddling as I work towards the next version :)