Troublesome arrow problem

Discussion in 'Plugin Development' started by dxwarlock, Jun 26, 2012.

  1. Offline

    dxwarlock

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I seem to have run into a roadblock...Making arrows from player that have a 'spread' pattern.

    using "player.launchProjectile(Arrow.class)" works WONDERFULLY for making a player shoot an arrow, but I cant seem to set a 'spread' to it. so if they are shooting a 'pack' of them it just makes them all go to the exact same spot.

    using player.getWorld().spawnArrow I can set a speed and spread, but how to make it look realistic for picking where they are aiming is beyond me..

    this is what I have so far:

    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerInteract(PlayerInteractEvent event) {
    4. final Player player = event.getPlayer();
    5. Action action = event.getAction();
    6. if (player.getItemInHand().getType().toString() == "BOW" && (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK))
    7. {
    8. for(int i = 1; i < 6; i++){
    9. player.getWorld().playEffect(player.getLocation(), Effect.SMOKE, 3);
    10. player.getWorld().playEffect(player.getLocation(), Effect.CLICK1, 3);
    11. Arrow arrow = player.launchProjectile(Arrow.class);
    12. arrow.setVelocity(arrow.getVelocity().multiply(2));
    13. }
    14. }
    15. }
    16.  


    which works GREAT, other than I cant figure out how to make them "spread' a little so they do a 'shotgun' effect.

    Anyone have any ideas how to get this?
  2. Offline

    ferrybig

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    arrow.setVelocity(player.getLocation().getDirection())
    I think that is good
  3. Offline

    dxwarlock

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I tried that too, it does the same as what I have..but not add 'spread'
    like "world.spawnArrow" has as an option for.

    so say I loop it 6 times, I get 6 arrows that all hit the same exact spot. :\
  4. Offline

    Squish000

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Try just changing the velocity of the arrow by random numbers so simulate spread.

    Code:
    a.getVelocity().add(new Vector(randomnumber(),randomnumber(),randomnumber()));
    I haven't tested this so it might now work as suggested.
    dxwarlock likes this.
  5. Offline

    ferrybig

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    random random;
    arrow.setVelocity(new vector(
    arrow.getVelocity().getX()+((random.nextFloat()-random.nextFloat())/10),
    arrow.getVelocity().getY()+((random.nextFloat()-random.nextFloat())/10)
    arrow.getVelocity().getZ()+((random.nextFloat()-random.nextFloat())/10)
    );
    dxwarlock likes this.
  6. Offline

    dxwarlock

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    that's perfect! thanks to both of you!
  7. Offline

    FozZeW

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Can u show me your working code please? I used


    Arrow arrow = player.launchProjectile(Arrow.class);
    Random random = new Random();

    arrow.setVelocity(new Vector(
    arrow.getVelocity().getX()+((random.nextFloat()-random.nextFloat())/10),
    arrow.getVelocity().getY()+((random.nextFloat()-random.nextFloat())/10),
    arrow.getVelocity().getZ()+((random.nextFloat()-random.nextFloat())/10)
    ));
    but arrow still goes straight

Share This Page