How to effective use short and recurring particlesystem

Hi Board/Deltakosh :slight_smile:

I recently created a particle system which is a laser hit on a space ship. It is just active for 500ms and then it disappears.
Currently every laser hit creates a new particle system and I thought it might somehow ineffective. Is there a better way to do it? Maybe similar to instances which can be used for meshes?

Thank you!

Hiya Alex.

I believe you would be interested-in particleSystem.manualEmitCount.

It doesn’t use a timer, though a timer CAN be used as well. It uses a pulse of particles (an amount of particles). The particle system keeps running… and anytime you set particleSystem.manualEmitCount to some value, it emits THAT MANY particles. ParticleSystem.minEmitPower and .maxEmitPower are STILL active… but ps.emitRate is not used or can be set to 0 or null or something or not-set at all.

http://www.html5gamedevs.com/search/?&q=manualEmitCount&type=forums_topic&nodes=28,29,30,31,38

Quick playground demo showing periodical .manualEmitCount settings: https://playground.babylonjs.com/#206JUO#22

I hope this helps. Single “laser” system… periodically/on-demand… dump photons into its “hopper”. :slight_smile:

1 Like

@Alex -

To expand on @Wingnut recommendation - I think he has ADD sometimes…:upside_down_face::upside_down_face:

Without a scene to reference, we can only guess as to why you might be setting up a different particle systems for each mesh. I generally set up a single particle system for each type of particle; and then apply the particle system as you would a material for any given mesh. Defining duplicate paticle system is just a waste of resources.

Again, think of a particle system as a material application. These both work in similar ways when applying to a mesh. A particle system is simply best defined as a variable - then it can be applied to any mesh on demand without re-defining.

Galen

1 Like

Oh, Alex was talking about the IMPACT points and not the shot itself? ohhhh. I should read more carefully. :slight_smile:

(one of WIngy’s eyebrows goes up, and the other goes down)

Me thinks he could have laser-hits on 5-10 mesh at once. Fast shooter. Each one has it’s own particleSystem spewing debris/smoke/fire.

Maybe I’m corn-fused, though.

1 Like

Hey both!

Thank you for your replies. The need is following: Imagine a star destroyer and multiple small ships. Tie Fighter and X-Wings for examples. And multiple ships are firing at the same time and there are multiple laser hits at the same time. For each hit there should be an effect like some sparks. Of course those effect has to be at this location where the laser hits the enemy ship.

My current solution is one GPU particle system which emits where a laser hits. After 300ms it is moved to a location where nobody can see it. It will change the location again when the next laser hits a target (thats a workaround, because particles doesn’t despawn when a GPU particle system stops).

You can have a look at the current state there: xvt (WASD, Arrow keys, Space for laser) You should fire at the star destroyer, but the hitbox is very big, so keep some distance when firing. Loading time could be high because the models are quite large.

Later, when there are more ships firing simultaneously I would need more gpu particle systems with a flag if its in use or not and just take the next unused one. But maybe I will find another solution for that. It feels still a bit dirty :slight_smile:

@Alex -
Sounds like you you’ve got a plan. However, I do not recommend keeping emitters and particle systems in your scene any longer than while it is emitting particles. There are exceptions of course, but I find that I can manage memory and optimize my scene much better if I dispose of emitters and particle systems when not in use. This is a much cleaner way to manage your scene and your resources. It’s a practice that I don’t personally see utilized enough. And I doubt most developers are in the habit of disposing of elements when not in use.

@Wingnut -
I get what you are referring to, as a scene might require multiple emitters depending on varying particle systems. But this generally does not require defining multiple particle systems; unless your scene requires multiple unique particle systems due to dramatic changes. Otherwise it is a waste of resources to define the same particle system more than once.

One modification to particle systems that I might recommend is that I often set the lifetime and other settings with variables so that I can control these values based upon the desired display time. So if you make the settings dynamic, you can use the same particle system and display different results using multiple emitters. Particle systems are already defined in a range between values, and you can expand this further if you set these values with variables. I often use random number generators as well to generate different display values using the same defined particle system. This way, I generally don’t need to define a particle system more than once… and I simply call these with a function when they’re needed in my scene. Then once the emitter is inactive, I’ll almost always dispose of the emitter and particle system to save on memory and GPU. I find that this provides me with a substantial boost in frame rate. Otherwise I find my frame rate lowered if the emitters and systems remain in the scene. So do a test - dispose of your emitters and particle systems and watch your frame rate immediately climb.

Galen

For reference… below is a typical particle system and function which calls the system that I generally copy into a scene to get me started –

export const generateSadContrails = (rootNode, scene) => {
const ConTrailSad = BABYLON.MeshBuilder.CreateCylinder(‘ConTrailSad’, {
diameterBottom: 0.48, diameterTop: 0, height: 1.5, tessellation: 30
}, scene);
ConTrailSad.rotation.x = -Math.PI / 2;
ConTrailSad.position.x = -0.5;
ConTrailSad.position.z = -3.3;
ConTrailSad.position.y = -100;
ConTrailSad.visibility = 0;
ConTrailSad.parent = rootNode;

// Sad Con Trail particle system
const ConParticleS = new BABYLON.ParticleSystem(‘ConParticleS’, 400, scene);
ConParticleS.particleTexture = new BABYLON.Texture(’./Demos/images/flare.png’, scene);
ConParticleS.emitter = ConTrailSad;
ConParticleS.minEmitBox = new BABYLON.Vector3(0.5, 1, 0.5);
ConParticleS.maxEmitBox = new BABYLON.Vector3(0.5, -1, 0.5);
ConParticleS.color1 = new BABYLON.Color4(0.1, 0.1, 0.1, 1.0);
ConParticleS.color2 = new BABYLON.Color4(0.2, 0.2, 0.2, 1.0);
ConParticleS.colorDead = new BABYLON.Color4(0.2, 0.2, 0.2, 0.0);
ConParticleS.minSize = 0.3;
ConParticleS.maxSize = 1.5;
ConParticleS.minLifeTime = 0.01;
ConParticleS.maxLifeTime = Math.random() * (0.1 - 0.01) + 0.01;
ConParticleS.emitRate = 200;
ConParticleS.blendMode = BABYLON.ParticleSystem.BLENDMODE_ONEONE;
ConParticleS.gravity = new BABYLON.Vector3(0, 0, 0);
ConParticleS.direction1 = new BABYLON.Vector3(0, 0, 0);
ConParticleS.minAngularSpeed = 0;
ConParticleS.maxAngularSpeed = Math.PI;
ConParticleS.minEmitPower = 0.1;
ConParticleS.maxEmitPower = 1;
ConParticleS.updateSpeed = 0.005;
ConParticleS.start();
};

1 Like

Really nice game prototype, Alex, and great assets ! I like this :slight_smile:

My own (old) tribute to the (very old) StarWars Atari arcade game : StarFighter

1 Like

@jerome -

Very nice::grinning: I hadn’t played this demo before. Good sound effects and GREAT ship explosions. Now if you can just get the death star trenches happening…

@Alex - Great Battle Cruiser! Are you going to do more work on this to make it a playable game? I know it’s allot of work for little payoff, but you already have such nice models and rendering in place. I don’t often see quality as we see in your Star Wars tribute. Expanding on the Battle Cruiser would be nice as well. I’d save this for Christmas as well… it would look great with a Cristmas theme on Christmas morning. I have to say it’s been something I’ve looked forward to recently; waking up Christmas morning to a new babylon.js scene playing Christmas music and wishing everyone on the forum a Merry Christmas! Seriously!

Galen

1 Like

@jerome Nice StarFighter game :slight_smile:
Thank you! The assets are all free from sketchfab from user called “Daniel”. I have a ton of other star wars ship models from him. I personally have about -3 experience skills when it comes to 3d modeling or 3d modeling software like blender.

@Galen For me it feels also cleaner if you dispose stuff, when not needed anymore. But creating new particle systems on demand caused frame drops, even with only one active ship firing. Maybe I have to switch to the normal particle system without GPU. Then I can stop the particle system and don’t have to teleport it to a place where no one can see it :slight_smile:

Yes I plan to make a multiplayer game. At the end it should feel like the old x-wing vs tie-fighter game, but with better graphics.
The “missions” shall be auto generated. For example the rebells have to destroy some containers and the imperials have to escord it and so on.
I really would just like to play a game like this with star wars feeling, but since x-wing alliance, there was no other game, that feels like this. So I have to do it by my self. And for the first time, thanks to babylon.js and threejs, I feel I can do a lot of work by my self.

Thank you all for answering.

Btw. I’m looking for collaborators :slight_smile: