How do I change particles movement after they are fired

  • I use particles (one-shot type) to create "infection spray" between two objects.

    Object A "sprays" particles to object B and that object B becomes "infected".

    The problem is that object B can start moving while particles are still flying towards it. And then this happens:

    http://doptrix.com/C2/SprayDemo/

    I want particles to change direction and continue following the moving object until they disappear.

    Of course I tried changing particles X and Y coordinates and pinning them to the target object, and of course this didn't work.

    Once the particles are fired, I can't control them.

    One workaround would be to spawn a bunch of small sprites, but this will require a lot of work to make them move like particles and also will be bad for performance.

    Is there any other solution or a trick that I can use?

  • The particle emitters aren't that flexible. They are more useful for generic sort of particles. If you want more specific behaviors for your particles, you'll need to spawn them yourself and control their movement with events. One thing I do in this case is recycle particles, so that I don't keep creating and destroying them. I only create more if there are none available or if I have set a limit on the number. Then whenever a particle finishes its motion/behavior I move it offscreen and disable it. When I need it again, I take them from that pool of particles that is offscreen. I also disable their collisions if it isn't necessary to help improve performance.

  • Why do you recycle particles? Does it really improve performance comparing to spawning/destroying?

  • I have noticed that it improves performance for my games. I don't know exactly why. I'd be interested in finding out though.

  • This will not work for me - I have many different particle objects and they are spawning randomly, there could be none or many at the same time on the screen. Recycling them would be a tricky task, much easier to spawn and destroy.

    And anyway, this wouldn't help me with my original problem...

  • Hey dop2000!

    You definitely would have to use your own tailor-made particle system. In the built-in particle system particles are not independent entities. Once they're "shot" by the generator, you doesn't have control of their movement.

    So, my suggestion would be you go for the spawn/destroy system, no recycling if that is a mess for you, and make some performance tests. Maybe it won't affect your final result that much. Also, do ALL your particles need this kind of control? 'Cause you could just stick to the built-int particle system for the ones that doesn't and save performance, while using your own particle system for the ones that do...

    Cheers.

  • Thanks, brunopalermo.

    I kind of knew from the start that I'll have to convert them to sprites. This post was my last attempt to find another solution.

    I have about 5-6 particle objects that need converting. I'll have to sacrifice some of the nice visual effects that I made with particles, because it will be just too much work coding them.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Yeah, dop2000... I guessed it was a hail mary. Been there, done that.

    But you may be more successful in converting them than you think. In the end, they might even be better looking, than the initial approach.

    Also, if you care to share a capx with just the particles you have now, I'd love to try and convert them... Just for the challenge and bbbecause it may be useful in the future. Two minds work better than one.

    Cheers!

  • Thanks, but this isn't actually a challenging job, just boring

    Add bullet and fade behavior, randomize all settings on creation, further randomize some of them on every tick.

    One definite advantage of sprites over particles is that I can rotate individual sprites to a random degree. With particles I can only change their angle of motion, but not the angle of image itself.

    Oh, and frames! I can create several frames and select them at random. I'm already excited!

  • Yeah. Already got it working. CPU use is 6% higher with the sprites. Using a continuous rate of 100 particles.

  • Does it help any if you recycle the sprites, brunopalermo ?

    Also have you disabled their collisions?

  • I didn't test it recycling sprites. Will do at some point. And, yes, collisions are disabled. Until now it seems fine in terms of performance...

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)