send projectile back to player

Discussion in 'Spigot Plugin Development' started by TheFuzzyHead5, Jun 3, 2017.

  1. Imagine this:

    Player shoots target

    I'm using the entdamagebyentevent and am making it so that when a projectile hits the target (and the player is the shooter) it will instead spawn one at the target and shoot back to the player.

    I have everything sorted, I'm just stuck at setting the velocity of the new projectile to hit the target:

    Entity proj = player.getWorld().spawnEntity(player.getLocation(), EntityType.EGG);
    Vector v = HERE!!!
  2. md_5

    Administrator Developer

    This is gonna be really hard to do since I don't know the specifics of Minecraft gravity.
    Code (Text):
                Location target;
                Location player;

                Vector v = player.subtract( target ).toVector().normalize().multiply( 5);
    That will get you a vector of magnitude 5 in the direction of the player from the target, but the problem is it doesn't account for vertical falloff from gravity.


    This will get you started, but you'll need late high school / 1st year uni level physics or maths to do it accurately.
    • Like Like x 1