question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to add and remove particles in a ParticleSystem?!

See original GitHub issue

I’m writing a little game including some bullets and explosion. So I think using ParticleSystem is a good idea.

The problem is : adding and removing particles from the ParticleSystem are very often. In every frame , I need to compute each particle’s position and change them in the ParticleSystem Sometimes,when new bullet come or old bullet die,I also need to add or remove vertex in geometry in ParticleSystem.

Now my way to solve this problem is so stupid,it already make my FPS lower when I shoot bullet All I want is to find a fine way to make it optimistic !

My way is here if there is bullets in the scene every frame I update it like this

// First. remove the PS from scene
scene.remove( this.particles );

// Then. new a geometry and compute each bullet vertices's position,for they are flying!
this.geometry= new THREE.Geometry();
for(....)
    // to do some compute,then add vertices to geometry
    this.geometry.vertices.push( new THREE.Vertex( this.bullets[i].position ) );

// Then. new the ParticleSystem with the geometry
this.particles = new THREE.ParticleSystem( this.geometry, this.material );

// Finally. add it back to scene
scene.add( this.particles );

OK,it got no problem when I run it,but it’s really slow I think there is no need to do the ‘remove’,‘new’,or ‘add’ every time I just need to change the position of vertices and add or remove vertex There must be some ‘clever’ way

and I know

geometry.__dirtyVertices = true;
geometry.__dirtyElements = true;

maybe it can solve this problem? But when I add vertex it shows nothing added when I remove vertex the chrome totally stopped I must do something wrong

So,what is the right clever way? Thank you

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mrdoobcommented, Apr 15, 2012

That has nothing to do with the this issue. Better open a new issue with your new question.

0reactions
novemraincommented, Apr 15, 2012

Ok.I will try

Another question,how to do Collision-Detection using threejs? Maybe my words are not clear,do you know what I mean? For example,there are two helicopters in my game,if they get a collision they are supposed to explode So,how to detect if objects(in the scene) got Collision with other objects?

Thank you

Read more comments on GitHub >

github_iconTop Results From Across the Web

Everything to know about the PARTICLE SYSTEM - YouTube
Udemy: http://bit.ly/BRACKEYSMEMEverything to know about the Particle System in Unity!♥ Support Brackeys on Patreon: ...
Read more >
How to remove a particle from a particle system - Unity Forum
I'm using particles to create tracers from a gun. Every Update(), I walk through the .particles array and raycast from each particle to ......
Read more >
Using the Built-in Particle System - Unity - Manual
To animate a Particle System property, open the Animation Window with the GameObject containing the Animator and Particle System selected. Click Add Property...
Read more >
A particle system (article) | Khan Academy
While removing items from the particles array during a loop doesn't cause the program to crash (as it does with adding), the problem...
Read more >
Particle System User Guide | Unreal Engine 4.27 Documentation
To add an Emitter to a Particle System, use the context menu by right-clicking in the empty area in the Emitters Panel, or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found