Change local velocity of particle system

Im trying to get my head around this but cant seem to get it to work.

I have a ParticleSystem setup with localVelocity set to -1 on the z-Axis. Every other Axis is set to 0.

Now i want to set the velocity of the z-Axis to 0 via script.

Here is my code:

ParticleVelocity.prototype.initialize = function() {    
    this.entity.particlesystem.localVelocityGraph = new pc.CurveSet([

I also tried to just set the keys value of the z-Axis curve but it yields the same result.

this.entity.particlesystem.localVelocityGraph.curves[2].get(0) = 0;

Why is this not working?


Here are the results:

In Editor (Velocity -1)

In Editor (Velocity 0) (this is how it should look like)

Set by Script (Velocity 0) (this is how it looks)

Do you have an example project we can look at please? It looks like you have setup a curve on the X axis rather than all 3 axes.

The project im working on is private, but i quickly set one up:

1 Like

I’ve found the problem, it wasn’t obvious and our documentation needs improving in this area .

It looks like when the randomize option is unticked in the Editor, it sets both localVelocityGraph and localVelocityGraph2 as the same value because they represent the min and max bounds of what would be the random range.

So the solution here is to set both localVelocityGraph and localVelocityGraph2 to the same graph.


Issue made to fix this:

1 Like

Ah this explains the issue.
Well i thought localVelocityGraph2 is null as stated in the docs.
I guess i should have logged it once :smiley:


Yeah, that’s now wrong :sweat: That’s what confused me till I looked at the engine code. The particle effect also looked like it was doing a randomised range to the extend of what the previous graph values were.

Haha thought the same. I was like does it cache the old value somewhere?

What would have happened is that the original curveset was copied to localVelocityGraph and localVelocityGraph2 so when localVelocityGraph was assigned a new curveset, it was randomising between the original curveset in localVelocityGraph2 and the new curveset in localVelocityGraph.

Sorry to bother again.

  1. If the velocity changes this is also applied to already spawned particles. Is there a way to make them keep their velocity and only newly spawned particles will be affected by the new velocity?

  2. If the lifetime/rate is changed the particle system is reset. Is there a way to prevent that so already spawned particles will remain?

I don’t think so unfortunately, the whole graph is rebuilt when it is changed. Having two particle systems that you turn on/off may be a better option here?

The idea was to implement a slider to change the ParticleSystem velocity. So there are no predefined speed values.
For now we discarded the particle approach maybe we can get a similar result by using a model and custom material/shader.

1 Like