[SOLVED] I need help with particles

How do you start a particle system with code because I’m trying to make a DBZ ( Dragon Ball Z ) fan game —> https://playcanvas.com/editor/scene/1143541

Hi,
To play a particle do:

this.entity.particlesystem.reset();
this.entity.particlesystem.play();

The “this.entity” is the entity that has the particle component attached, for doing other stuff check:

https://developer.playcanvas.com/en/api/pc.ParticleSystemComponent.html

2 Likes

thank you i’m still learning code

1 Like

is this right -->

var Kamehameha = pc.createScript('kamehameha');

// initialize code called once per entity.
Kamehameha.prototype.initialize = function() {
    
};

// update code called every frame.
Kamehameha.prototype.update = function(dt) { 
    //this is to fire the kamehameha wave.
    if(app.keyboard.isPressed(pc.input.key_K)){
        this.entity.particlesystem.reset('kamehameha');
        this.entity.particlesystem.play('kamehameha');
    }
};

No, the reset and play functions don’t accept the name of the particle as an arguement, the “this.entity” should have that particle system component attached to reset or play it.

You can check this project:
https://playcanvas.com/editor/scene/477031
And this script to see how to run the particle
https://playcanvas.com/editor/code/439297?tabs=5718307

1 Like

how about this?

var Kamehameha = pc.createScript('kamehameha');

// initialize code called once per entity.
Kamehameha.prototype.initialize = function() {
    
};

// update code called every frame.
Kamehameha.prototype.update = function(dt) { 
    //this is to fire the kamehameha wave.
    if(this.app.keyboard.isPressed(pc.KEY_K)){
    this.entity.particlesystem.reset = true;
    }
};

because it says it not working

Hi @the_amazing_ella! I’ve froked your project and seen that if you use the way of @Saad_Haider (so without any additions) it works as expected.

var Kamehameha = pc.createScript('kamehameha');

// initialize code called once per entity.
Kamehameha.prototype.initialize = function() {
    
};

// update code called every frame.
Kamehameha.prototype.update = function(dt) { 
    //this is to fire the kamehameha wave.
    if(this.app.keyboard.isPressed(pc.KEY_K)){
        this.entity.particlesystem.reset();
        this.entity.particlesystem.play();
    }
};
1 Like

thank you i have a coder helping me and we both were struggling with this