Solved Shoot arrow to a location

Discussion in 'Spigot Plugin Development' started by KarmaConfigs, Jan 7, 2020.

  1. My problem here is that I want to shoot an arrow to a nearby entity, so, the location is not permanent and for sure, the arrow direction has to change, I've tried by setting velocity, changing the rotation, trying with invisible armor stands, but nothing, I didn't found the way to do it.

    I checked a lot of posts, I searched a lot of google, this my latest way to, any idea to do it?
     
  2. Well, I just got this working by having the following code executed repeatedly by a BukkitScheduler:
    Code (Text):
            Location projectileLocation = projectile.getLocation();
            Location targetLocation = targetEntity.getLocation();
            final int   veloX = targetLocation.getBlockX() - projectileLocation.getBlockX(),
                        veloY = targetLocation.getBlockY() - projectileLocation.getBlockY(),
                        veloZ = targetLocation.getBlockZ() - projectileLocation.getBlockZ();
            projectile.setVelocity(new Vector(veloX, veloY, veloZ).normalize());
     
    It may need some adjustment but this is the way you can go.
     
    • Agree Agree x 2
  3. It's working, as you said, I have to make it more precise, but its a good method to start with