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 @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { final Player player = event.getPlayer(); Action action = event.getAction(); if (player.getItemInHand().getType().toString() == "BOW" && (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK)) { for(int i = 1; i < 6; i++){ player.getWorld().playEffect(player.getLocation(), Effect.SMOKE, 3); player.getWorld().playEffect(player.getLocation(), Effect.CLICK1, 3); Arrow arrow = player.launchProjectile(Arrow.class); arrow.setVelocity(arrow.getVelocity().multiply(2)); } } } 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?
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. :\
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.
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) );
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