Solved Need help with the arrow velocity

Discussion in 'Spigot Plugin Development' started by Jens00, Jan 22, 2020.

  1. Hello, I've been trying to spawn an arrow in the world and let the arrow follow me. I've got the spawning part but I can't seem to get the velocity to work. This is my current code, the Vector vec is the one I found on google but that shoots my arrow around 1K block away.

    Code (Java):
    final Arrow arrow = towerLoc.getWorld().spawn(arrowSpawn.clone().add(0, 3, 0), Arrow.class);
    //final Vector vec = arrowSpawn.toVector().subtract(target.getLocation().toVector().multiply(-3));
    //arrow.setVelocity();
     
  2. In order to make the arrow follow you, you'll need to update the Arrow's velocity as you move / every tick (I think every tick might be better)
    Suppose you are at Point A and the Arrow is at point B. You can get the Vector pointing from Point A to point B by simply subtracting A-B. Then, you'd normalize the resulting vector and multiply it with a constant in order to get your desired goal velocity. You need to do the subtraction - normalization - multiplication process each tick, until the arrow has (for example) hit the target
     
    • Winner Winner x 1
  3. Thanks a lot, never tried to normalize the velocity vector