Solved Need help with particles

Discussion in 'Spigot Plugin Development' started by VivianMusic, Mar 18, 2020.

  1. I am trying to spawn a straight line of particles, but for some reason they just shoot all over the place instead of just being a single particle in the correct place...
    here is whats happening: [​IMG]https://i.gyazo.com/e115b44a55729fcf10df205843e4da2e.mp4

    Code:
    Code (Text):
            Location loc = player.getEyeLocation();
            World world = player.getWorld();
            double maxLength = 8;
            for(double d = 0; d <= maxLength; d += 0.1)
            {
                loc.add(loc.getDirection().multiply(2));
                world.playEffect(loc, Effect.DRAGON_BREATH, 1);
            }
    Edit: I am trying to get them to play in a straight line between location 1 and location 2 (not the above code).
     
  2. https://bukkit.org/threads/shoot-a-beam.361964/
     
  3. Code (Text):
        public static void shootBeam(Location fromLocation, Location toLocation) {
            try {
                if (fromLocation != null) {
                    Vector from = fromLocation.toVector(), to = toLocation.toVector();
                    if (from.getX() != to.getX() || from.getY() != to.getY() || from.getZ() != to.getZ()) {
                        Vector direction = to.subtract(from).normalize();
                        while (from.distanceSquared(to) > 1F) {
                            fromLocation.getWorld().spawnParticle(Particle.DRAGON_BREATH, from.toLocation(fromLocation.getWorld()), 0);
                            from.add(direction);
                        }
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    This uhhhh crashed the whole server
     
  4. Just Use World#spawnParticle. The problem with some particles is that certain values have different meanings, depending on the arguments passed. For example, a fire-particle can move along a certain curve if you set the amount to 0 (not sure if it‘s actually the amount or some other field). If you simply want to display a beam, just use the Method that takes the location as x, y and z coordinates and the amount (and the particle, of course)
     
  5. Dude you legit copy pasted the code I sent you. Read the whole insert you need to get out of rust loop if your goal is reached
     
  6. Actually got ahold of @finnbon the particle god and he walked me through it.