Get the distance

Discussion in 'Spigot Plugin Development' started by zKiller171, Jul 30, 2018.

  1. Hi, i have a question: how can i get the arrow distance when it hits a player?
     
  2. Arrow distance as in, how far it goes?
     
  3. Whenever X hits an Entity Y you can then do:
    Code (Java):
    X.getLocation().distance(Y.getLocation());
    It may not be accurate as the player can move while the arrow is on the air however you could possibly save the X's location when the arrow is fired and then retrieve it when it lands a hit.
     
    • Agree Agree x 1
  4. I was referring to the distance (blocks) that the arrow have traveled when shoots the player.
     
  5. Not sure how that didn't answer your question?
     
  6. I dont think that's something you can get from the arrow data itself. You could however. Get the player that fired the arrow and calulate the distance from the player to the player it hit.
     
  7. Also you could get when the arrow is fired. Save that location. Run a timer that checks when the arrow hits the ground and compare those two locations. Whichever you prefer.
     
  8. Why make it so complicated? My solution is by far the most convenient. A Map could be created storing an entity or whatever as a key and a location as a value. Whenever the arrow is fired save the entity(arrow) in the map with it's location as the value. By the time it lands with another event retrieve that entity(arrow) from the map and compare the distances.
     
  9. That's basicly the same as mine, but you are just using an event to see if the arrow landed. Where as i'm using a runnable to check (basicly creating the event on your own). But yes that would be better then using a runnable.
     
  10. Simply, just use the event onShoot and OnHit.
    Saves each position in each event and calculates the distance between this positions
     
    • Agree Agree x 2
    • Optimistic Optimistic x 1