Is there a way to do this easily with the current codebase? If not, I will prob. add it. I want to be able to have all of the particles in an explosion get sucked towards a single point. I could override step to modify gravity for each particle as a hack (using per-particle calculated gravity as the pulling force to said point), but I'd rather add this as a proper enhancement. Force towards said point could either be set/constant or set and weakened with distance (like real gravity).
Particle Systems Attractor/Gravity Well
(7 posts) (3 voices)-
Posted 2 years ago #
-
You can change the particle settings to allow this type of functionality without to much trouble just derive from the point particle or quad particle class and set the spawn points, number of particle. if you want to get really fancy you can dig down into the particle system code and switch things around to get a better effect.
Posted 2 years ago # -
Can you elaborate? I know that I can override step code to achieve this, but how can I do it by modifying accessible properties?
Posted 2 years ago # -
How I'd approach this, off the top of my head:
- Inherit PointParticleSystem
- Add a new struct/class called 'ParticleEffector' with the following members
- strength (float)
- radius (float)
- node (CocosNode)
- Add an array to the class called 'effectors'
- Add management functions to add ParticleEffortors to the particle system
-(void)addEffector:(CocosNode*)node radius:(float)r strength:(float)s;
-(void)removeEffector:(CocosNode*)node
- etc..Then, in the step: function, you can calculate the effect on each particles movement for each particle based on a number of effectors. A positive strength pulls a particle towards the effector, a negative pushes it away..
Posted 2 years ago # -
Good points Slipster. I like the idea of being able to add any number of affectors. I think force should either be constant across the space, or reduce via the inverse square law (toggle-able). Another field like maxAffectorRange could be used as a bounds limiter for affectors (if desired) -- I think this would be the equivalent of the radius var. you mentioned.
- Jason
Posted 2 years ago # -
As much as I want to do this now, I prob. am not going to. I've got some other deadlines approaching. :-(
Posted 2 years ago # -
seems like it'd be a lot of fun to code. If someone does this, please submit it back..
Posted 2 years ago #
Reply
You must log in to post.