Solved getLocation().getYaw() returning inconsistent data

Discussion in 'Plugin Development' started by nuclearmissile, Dec 26, 2014.

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

    nuclearmissile

    I use getLocation().getYaw() to get a player's facing direction in a plugin, which I then translate into one of the four cardinal directions. The code works fine, however there's a really strange bug...

    The getYaw() function doesn't seem particularly consistent in its output. Half the time rotations are from 0 to 360, while the other times it's from 0 to -360 in the other direction. Is this already a documented bug, or am I doing something wrong? Any suggestion on how I might reliably get the cardinal direction? Any help is much appreciated!
     
  2. Offline

    567legodude

    If I am not mistaken there should be a getDirection() method that you can call on the player.
     
  3. Offline

    nuclearmissile

    @567legodude There is indeed, but that just returns the vector. I am happy to calculate the rotation trigonometrically if necessary, but I was hoping there would be a more reliable way of getting the rotation straight in its degree form without extra calculations.
     
  4. Offline

    567legodude

    Here is what I would do:
    Check if the direction is less than 0,
    if it is, then do (direction) - 360 and take the absolute value of that. It should return the normal direction.
     
  5. Offline

    nuclearmissile

    Thanks, I will go ahead and try to fix it given the information you've given me so far!
    @567legodude
     
  6. Offline

    Totom3

    @nuclearmissile Not sure if that would change much, but maybe using getEyeLocation() instead of getLocation() would work? Just an idea I had.
     
  7. Offline

    mythbusterma

    @nuclearmissile

    It's not a bug, it's the behaviour of the Minecraft server. You'll have to be able to handle both of those cases.
     
  8. Offline

    nuclearmissile

    Ok I fixed it, I did use the addition of 360 when below 0 and it works nicely.

    @mythbusterma So you're telling me that this arbitrary inconsistency is intended? Even if it is it would be a pretty useless feature.
     
  9. Offline

    567legodude

    @nuclearmissile Glad it worked. But don't you mean to say subtraction, or did addition work for it?
     
  10. Offline

    nuclearmissile

    Nah I used addition, since it was always negative if it was bad. I'd subtract if it were up between 360 and 720 degrees.
    @567legodude
     
Thread Status:
Not open for further replies.

Share This Page