Create A Vector

Discussion in 'Spigot Plugin Development' started by eli.musgrove9, May 13, 2015.

  1. I am trying to spawn an arrow 20 blocks above a player, and set the velocity of that arrow toward the player at a high speed. How would I create a vector that is facing directly down and that has a high speed?

    And yes, I did read this. https://hub.spigotmc.org/javadocs/s...cation, org.bukkit.util.Vector, float, float)

    Current Code:
    Code (Text):
    for (Entity entity : player.getNearbyEntities(5, 5, 5)) {
                    if (entity instanceof Player) {
                        Player affected = (Player) entity;
                        Location ploc = affected.getLocation();
                        ploc.setY(ploc.getY() + 20);
                        affected.getWorld().spawnArrow(<Vector, Otherstuff Here>)
                        abilitycooldown.add(player);
                     
                    }
                }
     
    #1 eli.musgrove9, May 13, 2015
    Last edited: May 13, 2015
  2. This doesn't work. What can I change so the arrow is spawned 20 blocks above "affected" and go down rapidly?
    Code (Text):
    Vector v = new Vector(ploc.getX(), ploc.getZ(), 20);
    affected.getWorld().spawnArrow(ploc, v, 10, 10);
     
  3. Code (Text):
    Vector directionVector = pLoc.getDirection();
    directionVector.setY(20);
    directionVector = directionVector.normalize();
     
     
  4. Thanks! How can I put that into the shootArrow method? What should I replace the 10 and 0 with? I don't want it to spread, just point straight down and move quickly.
    Code (Text):
    affected.getWorld().spawnArrow(ploc, v, 10, 0)
     
  5. Parameters are spawnArrow(Location location, Vector direction, float speed, float spread)

    well that would be affected.getWorld().spawnArrow(ploc, directionVector, 0.6f, 0);
     
  6. This shoots the arrow up when I raise the velocity. Is it because of the normalizing of it?
    Code (Text):
    affected.getWorld().spawnArrow(pLoc, directionVector, 5f, 0);
     
  7. That's because we set the direction positive. add -20 instead of +20.

    directionVector.setY(-20)
     
  8. The arrow isn't going for the player. It is aimed about 10 blocks away? BTW: Thanks for the help!

    Code (Text):
    for (Entity entity : player.getNearbyEntities(5, 5, 5)) {
                        if (entity instanceof Player) {
                            Player affected = (Player) entity;
                            Location pLoc = affected.getLocation();
                            pLoc.setY(pLoc.getY() + 20);
                            Vector directionVector = pLoc.getDirection().multiply(10);
                            directionVector.setY(-20);
                            directionVector = directionVector.normalize();
                            affected.getWorld().spawnArrow(pLoc, directionVector, 0.6f, 0);
                            abilitycooldown.add(player);
                        }
                    }
     
  9. Ok I removed the .multiply(10); after Vector directionVector = pLoc.getDirection(). Is there any way to make the arrow move faster? Whenever I edit the 0.6f it goes off target.
     
  10. Yes. Multiply it after you set the Y.

    Code (Text):

                          Vector directionVector = pLoc.getDirection();
                            directionVector.setY(-20);
                          directionVector.multiply(3.0f);
     
    10 is extremely high speed.

    Sure, you can all type it in a single line.

    Code (Text):


    Vector directionVector = pLoc.getDirection().setY(-20).multiply(3.0f);
     
  11. Thanks!!! Quick question: Why did you choose 0.6 for the speed?
     
  12. Thanks! Quick question: Why did you choose 0.6 for the speed? Seems really random to me.
     
  13. Vectorial formula equation.

    Nah, just kidding. Trial and error.
     
  14. Because .10 is extremely fast; he was just generalizing it for you
     
  15. ^_^ Welcome to our Vectorial Wonders Topic! Hope you have a pleasant stay.
     
    • Funny Funny x 1
  16. I've been stalking this thread :p XD
     
    • Funny Funny x 1
  17. Lurker! :D Haha :) Well, I hope he got his Vectorial Issues Solved. and Here I am, doing vectorial stuff in a game, still not needing all that stuff that we did in highschool. Teachers full of creep.
     
    • Funny Funny x 1
  18. Haha :p
     
  19. Thanks for all the help everyone! I can finally finish this 3 hour problem up!
     
    • Like Like x 1
  20. No problem buddy:) Make sure to rep up, Sure helps around, especially for a new member that needs to gain some reputation.
     
    • Winner Winner x 1