Particles never always go in definite direction.

Discussion in 'Plugin Development' started by AppleBabies, Dec 13, 2015.

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

    AppleBabies

    Hello. I have this particle effect I have created. It's is supposed to be a wave of fire that damages an entity when I run the scheduler. This works okay, but the particles don't always make a radial wave that dampens. Sometimes it floats into the air, sometimes it travels beneath me, sometimes it works correctly. But because locations are messed up, it NEVER damages entities. I have my scheduler below. Any help would be very much appreciated!
    Code:
    public void run(PlayerInteractEvent e) {
                  final Player player = e.getPlayer();
                  final World w = player.getWorld();
                  new BukkitRunnable(){
                          double t = Math.PI/4;
                          Location loc = player.getLocation();
                          @SuppressWarnings("deprecation")
                        public void run(){
                                  t = t + 0.1*Math.PI;
                                  for (double theta = 0; theta <= 2*Math.PI; theta = theta + Math.PI/32){
                                          double x = t*Math.cos(theta);
                                          double y = 2*Math.exp(-0.1*t) * Math.sin(t) + 1.5;
                                          double z = t*Math.sin(theta);
                                          loc.add(x,y,z);
                                          w.playEffect(loc, Effect.MOBSPAWNER_FLAMES, 1);
                                          w.playSound(loc, Sound.GHAST_FIREBALL, 1, 1);
                                          for (Entity en : loc.getChunk().getEntities()) {
                                              if(en.getLocation().distance(loc) <1.0) {
                                                  if (!en.equals(player)) {
                                                      en.setFireTicks(20*5);
                                                  }
                                              }
                                          }
                                          loc.subtract(x,y,z);
                                        
                                          theta = theta + Math.PI/64;
                                        
                                          x = t*Math.cos(theta);
                                          y = 2*Math.exp(-0.1*t) * Math.sin(t) + 1.5;
                                          z = t*Math.sin(theta);
                                          loc.add(x,y,z);
                                          w.playEffect(loc, Effect.MOBSPAWNER_FLAMES, 1);
                                          for (Entity en : loc.getChunk().getEntities()) {
                                              if(en.getLocation().distance(loc) <1.0) {
                                                  if (!en.equals(player)) {
                                                      en.setFireTicks(20*5);
                                                  }
                                              }
                                          }
                                          loc.subtract(x,y,z);
                                  }
                                  if (t > 20){
                                          this.cancel();
                                  }
                          }
                                                
                  }.runTaskTimer(MagicBattle.getPlugin(), 0, 1);
     
Thread Status:
Not open for further replies.

Share This Page