# [Bug] Incorrect Yaw Calculation

Discussion in 'Bukkit Help' started by Scizzr, May 6, 2013.

Not open for further replies.
1. Offline

### Scizzr

Not sure where to put this. You'd figure there would be some sort of "Bug Reports" forum... But there isn't. So I'll just post it here and hope that it fits in.

Basically, there's a problem with yaw calculation all the way down to the NMS level. I hope at least one person can save a couple wasted hours (unlike myself) by reading this and knowing why they're getting values like 746 and -1285 for yaw.

When the player is looking directly South, the yaw is 0. Yaw counterclockwise of South up to -179.999[...] is negative. Yaw clockwise of South up to 180 is positive.
This is the way it should be. I'm using South because South is what is currently showing up as 0. In the past, this used to be North before the direction switch.

When you do a complete 360° circle counterclockwise, all yaw counterclockwise of due South past the complete circle is always a negative number
Yaw should be a positive number when clockwise of due South, up to 180.

When you do a complete 360° circle clockwise, all yaw clockwise of due South past the complete circle is always a positive number
Yaw should be a negative number when counterclockwise of due South, up to -179.999[...].

So basically yaw isn't being reset when it goes less than -180 and greater than 180, and it's also not respecting the fact that counterclockwise of due South should be a negative number and clockwise of due South should be a positive number.

float yaw = ((EntityLiving)((CraftLivingEntity)((LivingEntity)p)).getHandle()).yaw;
I also tapped into NMS code to see if it was calculated the same there, and it is. I guess this means that to do the yaw-based calculations that I do, I'll have to start using some ugly Location loc2 = loc.clone(); loc2.setYaw(o); 's everywhere.

tl;dr: yaw not correctly being calculated all the way down to the NMS level.

#1
2. Offline

Does it work? Does it do, what it is supposed to do? Would it be GoldPlating to fix it to suit YOUR model of geometry? Of course it works, because when you take sinus of both 45 degrees and 405 degrees , the result is the same.

#2
3. Offline

4. Offline

### Necrodoom

not sure what you are getting at. not seeing any issues with yaw/pitch calculations myself.

#4
5. Offline

### pokuit

I have same problem

#5
6. Offline

### Bobcat00

I'm seeing:

S -> W -> N
0 -> +90 -> +179

S -> E -> N
0 -> -90 -> -179

Not sure if north is -180 or +180.

So how does this differ from what you're seeing, and what do you think you should be seeing?

#6