Solved Spawning arrow in player's direction

Discussion in 'Plugin Development' started by KingFaris11, Apr 26, 2014.

Thread Status:
Not open for further replies.
  1. Hello, I'm making an item launch an arrow at the direction the player's facing, the problem I'm having is that the arrow is shown as pointing in a different direction for the first quater of a second of it being spawned, but then fixes its direction after and it does land in the right direction. It does shoot at the right direction, just pointing at the wrong place, as if it's pointing towards the player.
    Code:
    Arrow bulletArrow = player.getWorld().spawnArrow(player.getEyeLocation().add(player.getLocation().getDirection()), player.getLocation().getDirection(), 15F, 0F);
    bulletArrow.setShooter(player);
    
     
  2. Offline

    rfsantos1996

    On vector arg, try recreating the vector with the location of the player and it's direction instead of just using getDirection
     
  3. Code:
    Vector directionVector = new Vector();
    directionVector.setX(player.getLocation().getDirection().getX());
    directionVector.setY(player.getLocation().getDirection().getY());
    directionVector.setZ(player.getLocation().getDirection().getZ());
    
    Tried it - didn't work. :(
    rfsantos1996
     
  4. Offline

    mrgreen33gamer

    Soo, your trying to make it were the arrow shoots faster?
     
  5. No, I know how to make the arrow shoot faster, I want to know how to fix the problem where the arrow isn't facing the right way.
     
  6. Offline

    mrgreen33gamer

    Ohhhh, lol, let me make a code for you.

    Here ya go!

    Code:java
    1.  
    2. @EventHandler
    3. public void onGoArrow(PlayerInteractEvent event){
    4. Player player = event.getPlayer();
    5.  
    6. if(event.getAction() == Action.RIGHT_CLICK_AIR){
    7. if(event.getItem().getType() == Material.STICK){
    8. Arrow arrow = (Arrow) player.launchProjectile(Arrow.class);
    9. }
    10. }
    11.  
    12. }
    13.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  7. Thanks for trying - but there's no way of setting the speed for this. :( Or is there... Would multiplying the vector (direction) by 5 work?
     
  8. Offline

    mrgreen33gamer


    Hold on, :p I can do this, i have been coding since i was 8 :p
     
  9. Friend fixed:
    Code:
                                Arrow bulletArrow = player.launchProjectile(Arrow.class);
                                bulletArrow.setVelocity(player.getLocation().getDirection().multiply(5));
    
    Thanks for the contribution mrgreen33gamer !
     
  10. Offline

    mrgreen33gamer

    LOL! I was just about to send you a code JUST LIKE THAT!
     
    KingFaris11 likes this.
Thread Status:
Not open for further replies.

Share This Page