SolidParticles, Mesh, TransformNode and Ray

Dear Babylon-Community,

I’m planning to optimize my projectiles (i.e. laser shoots) and have some new ideas and regarding questions.

  1. It works to use ray = new BABYLON.Ray(mesh.absolutePosition, direction, length), so they stick together liked parented, but why does it not work with transformNode instead of mesh? Maybe a new feature to be added? Or another solution that you don’t have to create a ray each frame per shoot (mesh or solidParticle).
  2. Is it possible to use a SolidParticle as parent of TransformNode?
  3. When do you use buildMesh, because every time a shoot is done is bad in terms of performance? Do you store all projectiles to be created in sps and work down that list at some point?

If you can find my blaster fx playground that might be easier to break down how to build an sps that can do all sorts of cool weapon effects.

It’s best to end up caching all the different elements, and then make a method to grab the next unused one and do all the logic associated with it.

I have a “particle master” playground too that if we can find it has a class for constructing complex sps effects easier.


Here is the one with the Particle System class. I can’t find the most up to date one but this has most the stuff.

There is a “master” class but the stuff you would be more interested in is how the particle systems are constructed.


Thanks a lot for your help.

It will take some time for me to understand everything. For now I will focus on your Particle System, how to keep up performance on expandable SPS, because mine does sps.buildMesh() every add/remove of particle (laser shoot):

Ok, I have my first question, because I’m using .js-files and upto now all I really learned is to use import/export but it seems that it won’t work for interfaces. Do I have to switch (partly) to typescript? If yes, how I do this? Or is it recommended to switch to something like a package that can access all my files without import/export? I’m using index.php, index.js and bootstrap.js if this is relevant.

Interfaces are only for typescript.

1 Like

I see. Hopefully my change to javascript will work, but I have more questions about your SolidSystem:

  1. about your OnRecycle-function: Can I set maxDistance:0 and speed:0 in particle.props, because you have values here? They shouldn’t move or have a max travel distance while on recycling?

  2. about awakeParticle-function:
    2.1. Is it necessary to set scale to 1, because it will be increased on its own by the Update-function? Or did I miss something?
    2.2. Do I set velocity directly like you did or is it better to use speed*direction? FYI: I can calculate the direction before or by using an additional property I could do this inside Update-function. Atm I’m using an additional property the firepoint (transformnode) to get absolutePosition & absoluteRotationQuaternion.

  3. about OnUpdate-function: Can I create rays in particle.props (if timeAlive==0) that are then evaluated if they certain intersectsMeshes and on intersection call group.killParticle(particle.idx) to remove it? Then do your movement part.

  4. about order in onBeforeRenderObservable.add: I’m working on a RTS-like game would this be the correct order?

calculations of delta
=> solidManager.update, where intersectionEvaluation is done
=> getTarget, rotateWeapons, group.awakeParticle

I did this order, because when I thought it through, the intersection should be evaluated before the particles move. And before particles are “created” the ones from the frame before should move.

Edit: I got it working! You have to subtract groupCachePoints[0] from groupCachePoints[1] when adding new group, else idx are wrong. When you want to use multiple groups. Also the !this.groups.keys.length had to be changed to this.groups.size in javascript.

1 Like