# [1.12.2-R0.1] Determining yaw based off of two locations

Discussion in 'Spigot Plugin Development' started by GreatThane, Jun 10, 2018.

1. ### GreatThane

Hello again,
I'm running into a slight issue that for the life of me I cannot find the solution to.
What I'm attempting to create is a "laying down" simulator (more akin to laying prone in most shooter games than the traditional bed laying you see on most servers that is generally limited on mobility)
And for the most part, it's working perfectly!

Only one slight issue: That account is looking at the camera right now.
See, the way I am forcing the player's first person perspective is through the elytra flight tag, which places his camera into his feet. However, the player model is a block forward, and I want the player head to be in the same location in both first and third person. To do this, I hide the player and create a fake player, setting their position a player's height behind the actual player (through their location's direction multiplied by negative 1.8-ish).
the only problem is the yaw refuses to work correctly. I'm attempting to get the player head to be in the player's location, while the feet stay in their designated location.
Basically, what I have is two locations and a yaw. However, no matter what I try to set the yaw to, it is never 100% correct.
Yaw's I've tried include: setting the player's yaw. getting yaw based off the direction, getting the yaw based off loc1.toVector().subtract(loc2.toVector), and using this method: yaw = -atan2(dx,dz)/PI*180 (found on wiki.vg)
My question is, does anyone have an idea on how I could accurately place the player head in the desired location? Or am I off on a red herring and need to go try something else entirely.

2. ### wytrem

As far as I understand, shouldn't you compute the second location based on yaw and not the opposite?
How do you compute the second location?

After some experiments, it looks like a 0° yaw corresponds to "facing towards positive Z" and a -90° yaw corresponds to "facing towards positive X". Maybe you could try -atan2(dz, dx) ?

3. ### GreatThane

I attempted this, however, this was the output:
(https://kek.gg/i/5WFKYb.gif)

and for -atan2(dx,dz)/PI*180:
(https://kek.gg/i/7PB8L4.gif)

and by setting to the player's yaw:
(https://kek.gg/i/53cxt7.gif)

however, none place the head in the proper location (the center of the shadow's circle)

4. ### wytrem

Are you sure the center of the shadow's circle is on pos1? I think the client can only render shadow at real entity position (feet).
If you want the head of the fake player to be placed on the feet of the real player, you'll need to compute the feet position of the fake player based on real player's yaw. How do you do it?
For debugging, maybe you could make the real player visible so we can see where his actual position is.

Edit : after a quick look insinde the client sources, the only state that changes the player's model render offset seems to be sleeping. Maybe, by simulating sleeping, we could place the shadow under the head?

5. ### GreatThane

I'm not sure what you mean by shadow, but this is what the character looks like show:
(https://kek.gg/i/5MMdT.gif)

(This is when the yaw is set to the player's)
As you can see, it's off until the player stops turning, and in most cases the fake player snaps back into the correct position.