Jump to content

Particles properties over time


Recommended Posts

Is it possible to set a startColor for particles ? I know there is color1, color2 & colorDead, but i want to avoid the "pop" when a particle is emit, and for that i want to set a full transparent color, which gradually switch to color1 & color2.


Also, it could be cool to tell a particle that its size change over time (become bigger or smaller), i don't know if this option exist.

Link to comment
Share on other sites

Yes yes. On intialize you can create a time member and fill it and decide what to do over time. 

var timeInSec=var time = new Date().getTime()/1000; 

You can add that to each particle. 

p.timeInSec=var time = new Date().getTime()/1000;  on initialization. 

When you do the update you can decide what you want have happen. Maybe alter the scale over time? 


Link to comment
Share on other sites

Hi guys.  Let's take a look at some custom particle functions.


Right after I create the PS particle system in line 49, I set the customUpdateFunc in line 50. 

After that, myupdateFunction is used for updating... instead of the default one. 

In myupdateFunction, I no longer use color1, color2, and colorDead, and instead just make the particles change to a different random color each update cycle (lines 36-38).  Notice in lines 28 and 29 that each particle has an age and lifeTime properties, by default.  A simple if (particle.age > ???) {...} could easily be used in your custom update func.

Let's look at a standard default update function... https://github.com/BabylonJS/Babylon.js/blob/master/src/Particles/babylon.particleSystem.js#L99 .  Notice that a value called _scaledUpdateSpeed is used heavily... and that might be a helper for you, too, @V!nc3r.

My demo goes a bit further, and also uses a customStartPosition function, too.  (lines 58-148).  This is how I accomplished 24 emitters.  Notice that the installation of the startPositionFunction is not done the same (no line 50 for startPositionFunction)... so you must name your "override" function... startPositionFunction.   But I could have also done ps.startPositionFunction = myStartPositionFunction... and that would have worked, too.

All in all, study this playground a bit, and in no time, you will be making custom/override functions for our standard and SPS particle systems... with good success.  Party(cle) on!

Link to comment
Share on other sites

Very interesting question,

What i personally did, was that i made the particalsystem a "child" of the emitter, the emitter is then stored in an array of emitters (containing all emitters & particalSystems of my scene)

var emitter = [];

//function that creates a new emitter & particle system.. i don't have long so, need to get to work, so i'll only post critical points.

emitter[id].particleSystem = new BABYLON.ParticleSystem("particles", 2000, scene);

I then added a specific "updateType"(custom) Id to the particle system depending on what it is and what i want to change over time.

emitter[id].updateType = 1;

in my case 1 is for adding a "tail" to a moving ball of fire.(reducing the size of each particle as it gets older)

I then go though each emitter in the renderLoop, check the updateType and for updateType === 1, i reduce the size of the particles as they grow older :).

particles can be accessed from emitter[id].particleSystem.particles.

try to make a PG and play around with it, console.log to see what's what :) have fun and good luck!

hopefully this added another idea of how to work with particles.


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...