Tutorial Spawning a line of particles

Discussion in 'Resources' started by Deleted user, Nov 4, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Deleted user

    My first contribute to this forum section, I just wanted to point out that you need few lines of code to solve a problem which may seem impossible to the newbies.
    How do I get the line of locations?
    I think vectors are the best solution. For a minimal understanding, see [Tutorial] How to calculate vectors.
    Code:
    // You can start wherever you want, but remember yaw and pitch
    Location start = Player.getEyeLocation();
    // The distance between each point is a location built with the direction components
    Vector increase = start.getDirection();
    // Call this to get the next point on the line
    // Location.add(Vector) sets the object to the result, so we do not need to multiply the increase value by the point number
    Location point = start.add(increase);
    How do I spawn the particles?
    Read about the World.playEffect() method or use the ParticleEffect library.
    Where to find code to easily copy and paste?
    Instant shoot

    Code:
    Location start = Player.getEyeLocation();
    Vector increase = start.getDirection();
    for (int counter = 0; counter < 100; counter++) {
        Location point = start.add(increase);
        ParticleEffect.FIREWORKS_SPARK.display(0F, 0F, 0F, 0F, 1, point, 200D);
    }
    Making the particles not instantaneous
    You should use the BukkitScheduler provided by Bukkit. Read about the BukkitRunnable class.
    Code:
    Location start = Player.getEyeLocation();
    Vector increase = start.getDirection();
    Trail trail = new Trail(start, increase);
    trail.runTaskTimer(Plugin, 0L, 1L);
    Code:
    public class Trail extends BukkitRunnable {
        private Location start;
        private Vector increase;
        public Trail(Location start, Vector increase) {
            this.start = start;
            this.increase = increase;
        }
        private int counter;
        @Override
        public void run() {
            if (counter == 100) {
                cancel();
            } else {
                Location point = start.add(increase);
                ParticleEffect.FIREWORKS_SPARK.display(0F, 0F, 0F, 0F, 1, point, 200D);
                counter++;
            }
        }
    }
     
    Last edited by a moderator: Apr 30, 2017
  2. Offline

    Plugers11

    Hmm do scheduler to time particles ? :D
    Like wizards on Hypixel
     
  3. Offline

    Deleted user

    Plugers11 You can do it whenever you want. What's the problem?
     
  4. Joiner He doesn't know how to make it appear as if the particles are moving away from him, leaving a trail. For example, the particles close to the player appear first, then the particles out from there appear after.
     
  5. Offline

    ChipDev

    I would use a 'time' variable that increases every X ticks.
     
  6. Offline

    Deleted user

Thread Status:
Not open for further replies.

Share This Page