Sunday, December 23, 2012

Gradually 'freezing' particles


Sometimes I needed to gradually decrease the SPH-based particles velocity until they're completely stopped. A bounded Drag daemon is an effective way to apply a 'braking' force to your particles, but if you want to apply such forces in a smooth & progressive way, you may find interesting the following script that I made as an Event script. 

See a sample video here:



So, let's do it. First of all, press Ctrl + F2 to open up Simulation Events window and right clic over Frames Post.

In the pop up window add the following code (replacing the "Circle01" string with your emitter's name): Download
  • increment is the reduction factor of the velocity. Higher values means less reduction, for instance 0.99 will barely reduce the velocity frame by frame all along the timeline, while 0.10 will drasticly reduce the velocity of your particles in a short time.
  • threshold stands for the minimum velocity of the particle prior to get completely frozen.
  • minlife is the minimum life (in seconds) of the particle prior to apply the braking force.
Once your values are set up you just need to clic OK and Simulate.

You'll have noticed that the particles are frozen by setting up their velocity to 0,0,0 (what is described in the script as 'zero_velocity'). Once these particles are completely stopped they can still react and move if other particles collide with them. However you may want that once the particles are stopped in a first term, they keep completely frozen even though other particles / forces collide with them. In that case you just need to uncomment the particle.freeze() line by removing the ## symbols and add them to the previous line in order to comment the 'set velocity to zero_velocity' instruction.

IMPORTANT: Make sure your tabbing is OK if you copy/paste code. Your leading indents should appear pretty much like these ones (click on the image to enlarge):