Particles between two locations

Discussion in 'Plugin Development' started by Ward1246, Oct 17, 2015.

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

    Ward1246

    I am currently trying to play out particles between two locations, and I am using vectors to do so. I know that getting two locations of two objects, getting the toVectors, and subtracting them will get the distance I need, but I don't think this will work for particles.
    Code:
      double particles = 0.01;
                   Vector vector = a.getLocation().toVector().subtract(player.getLocation().toVector());
                   Vector amt = vector.multiply(particles);
                   double x = amt.getX();
                   double y = amt.getY();
                   double z = amt.getZ();
                  PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(EnumParticle.REDSTONE, isEnabled(), (float) (player.getLocation().getX() + x), (float) (player.getLocation().getY() + y), (float) (player.getLocation().getZ() + z), 4, (int) 0.4, 4, 2, 0);
                   for(Player online : Bukkit.getOnlinePlayers()) {
                         ((CraftPlayer)online).getHandle().playerConnection.sendPacket(packet);
    
    I tried looking up a way to use vectors to make a trail of particles, and I read that what was needed to be done was dividing the vector, getting the divided vector and it's x y z coordinates, then getting the players using the coordinates, and finally using the vector x y z coordinates to be added to the players location. I have changed and moved parts of code around, but nothing worked. I am not sure if this method won't work, or if I am doing something wrong, but either way any help would be greatly appreciated.
     
  2. Offline

    Scimiguy

    @Ward1246
    So you're trying to make a line of particles between two locations?
    Or you're trying to get the center between two locations and play particles there?
     
  3. Offline

    Ward1246

    Between two locations, one location is the player, the other location is an arrow.
     
  4. Offline

    Scimiguy

    @Ward1246
    Seems like you'd need to loop over all the locations between the the two Locations, playing particles on each of them.

    It may be worth reading through this thread to see how someone has done that already.
    Otherwise, it's mostly simple math getting the line you need
     
  5. Offline

    mythbusterma

    @Scimiguy

    There are infinitely many points between two points, you can't "loop" over all of the Locations between two points.


    @Ward1246

    If you're trying to make the arrow have a trail, why not just run a repeating task that spawns a particle at the arrow's location every tick? That would make the most sense to me.
     
  6. Offline

    Scimiguy

    @mythbusterma
    You would either Math.floor or Math.ceil
    C'mon myth, you know that lol
     
  7. Offline

    mythbusterma

    @Scimiguy

    So you would do it for each block between them, which is a finite number.
     
  8. Offline

    Scimiguy

    @mythbusterma
    Correct?

    Assuming he's picking two arbitrary points.

    If he's just trailing an arrow, your way is the best way obviously
     
Thread Status:
Not open for further replies.

Share This Page