Spawn slow fireballs random above player

Discussion in 'Plugin Development' started by silthus, Jun 2, 2013.

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

    silthus

    Hi,

    I am trying to spawn random fireballs above the player and have them fly down like small metors. But I have some problems with the vector calculation and the meteors are too fast.

    Here is the code I have so far. The method param Location is where the player is aiming and the metors should land.

    Code:
        public void dropMeteor(Location location) throws CombatException {
     
            // lets get a position above the location with a random offset
            Location origin = location.clone();
     
            for (int i = 0; i < getAmount(); i++) {
                origin = origin.add(MathUtil.RANDOM.nextInt(3), MathUtil.RANDOM.nextInt(5) + 3, MathUtil.RANDOM.nextInt(3));
                RangedAttack<ProjectileCallback> attack = new RangedAttack<>(getHolder(), ProjectileType.LARGE_FIREBALL, getTotalDamage());
                org.bukkit.entity.Fireball projectile = location.getWorld().spawn(origin, org.bukkit.entity.Fireball.class);
                projectile.setShooter(getHolder().getPlayer());
                projectile.setIsIncendiary(true);
                projectile.setFireTicks(100);
                attack.setProjectile(projectile);
     
                Vector direction = new Vector(location.getX() - origin.getX(), location.getY() - origin.getY(), location.getZ() - origin.getZ());
                direction = direction.normalize().multiply(MathUtil.RANDOM.nextInt(i));
                attack.setVelocity(direction);
                attack.run();
            }
        }
     
  2. Offline

    CoderCloud

    To slow the meteor down i would use: 'projectile.setVelocity(projectile.getVelocity().multiply(0.5));'
    Also the fireballs fired later are faster. The speed can be 5 times faster when the 5th fireball is fired, because you used'direction = direction.normalize().multiply(MathUtil.RANDOM.nextInt(i));'
     
  3. Offline

    Technius

    silthus
    Like CoderCloud said, you'll have to adjust some values. You will want to make the random number like this:
    Code:
    MathUtil.RANDOM.nextDouble()
    That creates a number from 0 to 1, so it can have no movement or go at full speed. You can make it a value between a range like this:
    Code:
    double min; //Minimum speed multiplier
    double max; //Maximum speed multiplier
    double speedmult = MathUtil.RANDOM.nextDouble()*(max - minx) + min;
    
     
  4. Offline

    silthus

    Technius, CoderCloud, mmh this only works partially. It slows the meteor down now, but it still very fast and when I multiply the direction it does not hit the player anymore.

    Isnt there a way to spawn a simple fireball like when a entity is shooting it, without the entity?
     
Thread Status:
Not open for further replies.

Share This Page