Solved Arrow Vector

Discussion in 'Plugin Development' started by Smartloser, Jun 20, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Smartloser

    I am trying to launch an error that'll be spawned in one location and be aimed to the other location.. this is my code:

    Code:java
    1.  
    2. final Arrow a = world.spawnArrow(startloc, new Vector(0,0,0), (float) 1, 20);
    3. a.setVelocity(this.endloc.getDirection().multiply(3));
    4.  

    The arrow does spawn at the start location I set to be, but it doesn't go to the endlocation, most of the time it goes to the opposite directions. I was wondering how to fix that, thanks.

    Regards,
    Smartloser
     
  2. Offline

    Rocoty

    To get the direction between two points in space, you need to be aware of both points, agree? So in line three of your snippet, you are only using the endLoc point. Which in practice means that this part of code is only aware of the endLoc point, and therefore cannot calculate the direction between the start and the end point.

    Bukkit Location objects can have their own direction set, but this is only a local one and is not helpful in this context. It is the one you get from getDirection().

    Basically, to calculate the direction vector between two vectors, you subtract the start vector from the end vector. A simple Google search will also tell you this and may give you more useful information.
     
  3. Offline

    Smartloser

    Thank you, working now. Why didn't I think of that lol
     
Thread Status:
Not open for further replies.

Share This Page