Get player facing axis

Discussion in 'Spigot Plugin Development' started by ARgoeclipse, Aug 8, 2018.

  1. Hello, I am currently trying to figure out if a player is facing towards a negative/positive x/z. Here are my current theories:

    1. Take angle difference between player location and a vector along x/z and do some calculation beyond that?
    Code (Java):

    // x axis angle difference
    Vector3 x_axis_ref = new Vector3(1, 0, 0);
    double diff = Math.acos(player.getLocation().dot(x_axis_ref) / (player.getLocation().length * x_axis_ref.length))
    // ???
    2. Take dot(a, b), and if the number is below 90, its negative, if its above 90 its positive? But how could I differentiate this from x and z?

    And corrections/pseudo code/extension to my ideas would be appreciated.
  2. A yaw of 0 means the player looks into +z, 90≈-x, 180≈-z, 270≈+x. Obviously values inbetween are a mixture.
  3. Wow. I was overthinking it way too hard. Thanks.
    • Like Like x 1