Spawning arrows

Discussion in 'Plugin Development' started by Jakeob22, Aug 5, 2012.

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

    Jakeob22

    Hello, I've been trying to make an arrow go forward from a player. The javadocs say that you can spawn an arrow with:

    spawnArrow(Location location, Vector velocity, float speed, float spread)

    I spawned it at the players location, with the players velocity, the speed 0.8F, and the 12F spread. It went strait down from the players head. I'm assuming it's the velocity. Can anybody help?
     
  2. Offline

    Phinary

    Try setting the velocity to:
    player.getLocation().getDirection()
    or
    player.getLocation().getDirection().multiply(2)
     
  3. Offline

    Jakeob22

    Thanks :D
    I'll try it right now.

    It didn't work. Do you want to join our test server and see our problem?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  4. Offline

    Phinary

    Try this. Not sure if it will work, but I think it is your best bet.
    Code:
    Location loc = player.getLocation(); // Get the player Location
    loc.add(0, 1, 0); //Add 1 to the Y, makes the arrow go at chest level instead of feet
    Arrow arrow = player.getWorld().spawn(loc, Arrow.class); //Spawn Entity
    arrow.setShooter(player); //Set the shooter to your player
     
  5. Offline

    Jakeob22

    Didn't work either, don't know what's wrong. :(
     
  6. Offline

    Gawdzahh

    Any more help on this guys?
     
  7. The arrow is colliding with the player and falls down, you need to spawn it in front of the player.

    Convert that direction into a normalized vector (just see the methods available and you'll see what I mean) then add that to the location and it should be in front of the player... keep the + 1 y addition as well so it spawns in front of your head, not your feet.
     
  8. Offline

    Gawdzahh

    I got it working, by setting the speed float to "1" it only shoots 1 arrow... Now how do i adjust the speed :S

    and It shoots behind the player, because of that +1 x but if i turn around...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  9. Offline

    Gawdzahh

    Got it too shoot for sure... Increased the speed... Just the accuracy is terrible since im using getEye Location for the location of the arrow.
     
  10. Offline

    kalicat

    try arrow.setFallDistence(0);

    or setFallDistence(10000)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  11. Offline

    moo3oo3oo3

    Where are the methods?
     
Thread Status:
Not open for further replies.

Share This Page