Increment Particle

Discussion in 'Spigot Plugin Development' started by FrostedSnowman, Apr 13, 2017.

  1. FrostedSnowman

    Resource Staff

    hi, im curious how i would increment a particle effect. for example a circle.

    i can make a circle from effects. however, how can i make it so that instead of the particle playing at each degree/radian then disappearing, or it all appearing at once, i make it increment. ex:

    particle displays at degree 1, then at degree 2, then at degree 3, BUT, it will not stop playing particles at degree/location 1 & 2, it'll keep going until it completes the circle.
     
  2. My first idea: put the "started ones" (the ones that have already been displayed) into a collection and display those and the new one as well each tick.
     
  3. FrostedSnowman

    Resource Staff

    i was thinking of storing the locations, then make a queue system or something, im not sure. any other ideas?
     
  4. This is easier than you might think. You'll have to use a combination of a for-loop and a (Bukkit)Runnable.

    First create your (Bukkit)Runnable and schedule it at a certain interval. Then add a double variable and add a certain amount to it everytime the runnable runs, just like you would normally do to make a particle effect walk along the circle.

    Here is where the for-loop comes in. You're gonna set up a for loop like this
    Code (Java):
    for (double rad = 0; rad < YOUR_VARIABLE; rad += SOME_INCREASEMENT_VALUE) {

    }
    Then put your circle code in the for loop and use 'rad' for the sin and cos functions.
     
  5. FrostedSnowman

    Resource Staff

    thanks, i'll try it out when I can!
     
  6. Place it in a BukkitRunnable instead of a for or while loop. Have the particle show for X milliseconds and after that time show the next particle for X miliseconds. Repeat until you have done 360 degrees
     
  7. FrostedSnowman

    Resource Staff

    i am already doing this, but i think you may have understood.

    i want to have for example a flame particle to start at Location 1 / degree 1 and then when it goes to Location 2 / degree 2, it'll keep playing the particle at Location 1. etc etc
     
  8. Yes. As an example, let's assume we have a list of Vectors (offsets from the circle's centre)
    Code (Text):
    circle = [
      vector(360 * (1 / n)),
      vector(360 * (2 / n))
      ...
      vector(360 * (n / n))
    ]
    You'll start with a single location, and each run you increment that value by one (so 1 particle, 2 particles, 3 particles, till n particles). You can simply use a for loop to iterate over the first x particles (for (i = 0; i < 1; i++) will run for i = 0, giving you only the first particle - as Java starts indexing by 0 :p - and at x == n, you'll get all n particles).

    For each vector you encounter, simply add it to the centre Location, and you get a particle location, where you spawn one.