Launch multiple projectiles from mob

Discussion in 'Plugin Development' started by opd02, Mar 25, 2020.

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

    opd02

    I am trying to get a ghast to sort of spam fire fireballs at the player rather than the lame one fire ball. I made it so they spawn more fireball, but the velocities are all messed up. The first (real) fireball goes to the player but the others sort of just shoot out straight. I think I just need help with the velocities. Please help!
    Code:
        @EventHandler
        public void onProjectileLaunch(ProjectileLaunchEvent e){
            Projectile p = e.getEntity();
            if(e.getEntityType()==EntityType.FIREBALL){
                if(!(p.getShooter().toString()=="CraftGhast")){
                    return;
                }
                Ghast g = (Ghast) e.getEntity().getShooter();
                Fireball ball = (Fireball) p;
                ball.setYield(7);
                g.setMaxHealth(100);
                if(list.contains(g)){
                    return;
                }
                list.add(g);
                task = Bukkit.getScheduler().runTaskTimer(this, new Runnable() {
                    @Override
                    public void run() {
                        if(i != 0) {
                            Projectile n = g.launchProjectile(Fireball.class);
                            n.setVelocity(g.getEyeLocation().getDirection());
                            Bukkit.getWorld(p.getWorld().getName()).playSound(g.getLocation(), Sound.ENTITY_GHAST_SHOOT, 3, 3);
                            i--;
                        } else {
                            i=4;
                            list.remove(g);
                            task.cancel();
                        }
                    }
                }, 3, 5);
            }
        }
     
  2. Offline

    CraftCreeper6

    @opd02
    Save the velocity of the initial direction and apply it to all subsequent fireballs.
     
  3. Offline

    NukerFall

    Try this thing:

    Code:
    Vector v = target.getLocation().add(0.0, target.getHeight()/2, 0.0).toVector().subtract(n.getLocation().toVector()).normalize();
                n.setVelocity(v.multiply(2.0));
                arrow.getLocation().setDirection(v);
    instead of your
    n.setVelocity(g.getEyeLocation().getDirection());
     
Thread Status:
Not open for further replies.

Share This Page