Solved How do vectors work?

Discussion in 'Plugin Development' started by Joiner, Aug 7, 2014.

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

    Joiner

    I need to understand how vectors work, how their mechanics work.
    I already know how to calculate them (https://forums.bukkit.org/threads/tutorial-how-to-calculate-vectors.138849/) but I can't imagine them.

    I can build a new instance with coordinates.
    Code:java
    1. Vector vector = new Vector(int, int, int);

    What do these 3 numbers mean?

    I can get a player direction.
    Code:java
    1. Vector direction = Player.getLocation().getDirection();

    Where he's looking is calculated using yaw and pitch, but how is calculated his speed? And how is that speed stored in the vector?

    Can you draw a simple picture to explain better a vector?
     
  2. Offline

    TheMcScavenger

    Vector(double x, double y, double z)
    Construct the vector with provided double components.
    Vector(float x, float y, float z)
    Construct the vector with provided float components.
    Vector(int x, int y, int z)
    Construct the vector with provided integer components
     
  3. Offline

    Joiner

  4. Offline

    AoH_Ruthless

    Joiner
    There is no simple way to explain this. The three double or integer values are x y and z coordinates. You have to understand vector algebra to be understand this proficiently.

    http://emweb.unl.edu/math/mathweb/vectors/vectors.html
    (Edit: While many topics on that tutorial are somewhat advanced and not necessary to know, you can create really cool effects with advanced vectors, and it's better to know more than you think you need)

    I tried to put together a little diagram:
    [​IMG]
     
    AdamQpzm likes this.
  5. Offline

    TheMcScavenger

    I kinda did. You asked what the three numbers mean, giving you the Javadoc information (clearly showing it's x, y, z) is a pretty good answer. If you still don't understand it afterwards, you shouldn't be here.
     
  6. Offline

    Joiner

    AoH_Ruthless Thank you very much.
    If a vector associate two locations, why the constructor requires only 3 coordinates and not 6?
     
  7. Offline

    Necrodoom

    Joiner it contains the difference of the 2 locations, not the locations themselves. You can apply this vector at any location you want and it wouldn't matter.
    See the last paragraph in the picture.
     
  8. Offline

    AoH_Ruthless

    TheMcScavenger
    Actually, your answer was not adequate at all. The OP doesn't understand the basic concept of a vector and needed assistance wrapping his mind on what they are and what they do. The Documentation does not thoroughly explain what exactly a vector is (it is assumed you have the required Algebra to be using them) and just telling him about integer components offers no help at all.

    Joiner
    Because a vector is not directly related to the locations themselves. A vector is just a linking line between two locations (the difference between them). If I applied a vector 10 blocks higher or lower, it would be exactly the same, just with a different start and end point. A Vector is nothing more than a line with magnitude and direction. You can have positive and negative vectors and a velocity associated. More information
     
  9. Offline

    Joiner

  10. Offline

    AoH_Ruthless

    Joiner
    In essence, yes. What are you trying to do exactly?
     
  11. Offline

    TheMcScavenger

    One of his questions was "What do these three numbers mean", meaning that my answer to that question was good enough for him to understand it.
     
  12. Offline

    Joiner

    AoH_Ruthless
    Nothing. I know how to use them, but I want to understand them, too.
    So, the 3 values represent the movement to each direction (X, Y, Z) in blocks. Is the speed calculated automatically? How?
     
  13. Offline

    AoH_Ruthless

    TheMcScavenger
    No, because the question about the meaning of the three numbers revolved around a lack of Vector understanding in general, not what an integer is.

    Joiner
    There is no speed in a vector. Vectors are lines with magnitude and direction.
     
  14. Offline

    Joiner

    Player.setVelocity(Vector) makes the player move. Movement = Direction (vector) with speed. How is the speed calculated?
     
  15. Offline

    AoH_Ruthless

    Joiner

    If I do Player#setVelocity(new Vector(1, 2, 1)), they will be propelled one block + in terms of x and z and 'jump' 2 blocks into the air. The vector is not defining the speed, but the the direction in which the player will travel.
     
  16. Offline

    Joiner

    AoH_Ruthless So, how is that speed calculated? Where is it defined?
     
  17. Offline

    LucasEmanuel

    Garris0n likes this.
  18. Offline

    Chiller

    Joiner A vector is a direction, speed is a magnitude, if you set player.setVelocity(vector(1, 2, 1)) the player will move 2 m in the y direction, aka jump.
     
  19. Offline

    coasterman10

    The speed is the vector itself. When you give them a vector with components (x, y, z), they will move at those speeds in the respective directions.
     
  20. Offline

    mythbusterma

    Uh no, they will jump up, slightly to the south-east.
     
    Garris0n likes this.
  21. Offline

    unon1100

    Vectors used for speed - The player will move the length of the vector in 1 tick.
    Vectors for direction - Directions that entities face are the x/y/z distance relative to the entities head. getting the length will return 1.
     
    Joiner likes this.
  22. Offline

    Joiner

    unon1100 Thank you very much.
    So, the player will have a speed of Vector.length() blocks/tick, right?

    AoH_Ruthless Why Player.getVelocity().toString() always returns "0.0,0.0,0.0"?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  23. Offline

    AoH_Ruthless

    Joiner
    Player most likely isn't moving ...
     
  24. Offline

    Joiner

  25. Offline

    Necrodoom

    Joiner same when player jumps?
     
  26. Offline

    Joiner

    Sorry, what do you mean?
     
  27. Offline

    Necrodoom

    Joiner when player jumps, velocity is also 0?
     
  28. Offline

    Joiner

    I was flying.

    Bump.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  29. Offline

    Joiner

    Thank you.
     
Thread Status:
Not open for further replies.

Share This Page