Set pitch and yaw towards a location

Discussion in 'Plugin Development' started by OracleTarget, Jul 31, 2014.

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

    OracleTarget

    Hey guys,

    How do I set a pitch and yaw towards a location? I don't really have a clue where to start. I really want to learn more about vectors, but I am still new to it. Can you give me some help or a good explanation about this topic?

    Thanks .
     
  2. Offline

    NathanWolf

    Vectors are not as complex as they seem! A vector is just a representation of a 3D point in space.

    A vector can also be used as a direction- in this case, it is a position in 3D space relative to the origin, that "points" in a direction away from the origin.

    So, to find the direction from point A to point B, you need to "force" point A to be the origin. Just like in normal math, if you have A and B and you want A to be 0, you just subtract A from B.

    So, given two Locations, locA, and locB - you can use Location.toVector to get vecA and vecB, the Vector representations of the Locations.

    You can then do Vector direction = vecB.subtract(vecA) to get a directional vector from A to B.

    And, finally- use the relatively new and very handy Location.setDirection (note how I had to link to the 1.7 javadocs for that) to set the pitch/yaw of a Location given a directional Vector.

    Hope that helps! Good luck, Vectors are super handy once you get your mind around it. Now Matricies... that's where things get complex. I wish Bukkit had summa dat magic built in...
     
  3. Offline

    OracleTarget

    NathanWolf
    Thanks a lot, this actually makes a lot of sense!
     
    NathanWolf likes this.
Thread Status:
Not open for further replies.

Share This Page