Unable to set position of a particle system

Hi all,

I’ve created a particle system entity that I clone on an event, enable it, position it and then play it. This works fine apart from the positioning - it stays where the original entity was.

BulletScript.prototype.onCollisionEnter = function(event) {  
    if(event.other.rigidbody === this.target.rigidbody) { 
        event.other.health--;
        if(event.other.health <= 0) {          
            
            var effect = this.explosionEffect.clone();
            effect.enabled = true;
            effect.setPosition(event.other.getPosition());
            effect.children[0].particlesystem.play();
            this.scoreCounter.element.text = parseInt(this.scoreCounter.element.text) + 10;
            
            event.other.destroy();
        }
    }
    this.entity.destroy();
};

That’s what my code looks like. I tried setting the position manually to (10, 0, 0) however the same issue happens. I also tried enclosing the particle system in a parent entity and positioning that to no luck. What gives?

Does this.explosionEffect have a rigidBody?

Are you able to share the project?

It does not have a rigidbody, it shouldn’t need it for a simple position set right?

Project is here:
https://playcanvas.com/project/568472/overview/typing-racer

It was more that if it did, it would explain why it didn’t move as setPosition can’t be used on an entity with a rigidBody to move it.

The particle effect was set at autoplay so when it gets enabled, it immediately spawns the particles where it currently is in the world (0, 0, 0) in this case.

Moving the enabled = true to after you set the position fixes this.

https://playcanvas.com/project/568650/overview/space-type-from-forums

        if(event.other.health <= 0) {          
            
            var effect = this.explosionEffect.clone();
            effect.setPosition(event.other.getPosition());
            this.scoreCounter.element.text = parseInt(this.scoreCounter.element.text) + 10;
            
            effect.enabled = true;
            
            event.other.destroy();
        }
1 Like

Perfect! Thank you so much