I have an direction that I want the local player hub & camera to rotate at. The game handles this by using euler angles which Y represents the hub rotation on the horizontal axis & X represents the camera rotation on the vertical axis.
The min-max range for vertical is -88 to 88 & min-max range for horizontal is 0 to 360
Here is the code I am using the create euler angles that will look onto the direction
Vector2 CalcEuler(Vector3 dst, Vector3 src)
{
//dst is target position, src is maincamera position
Quaternion quat = Quaternion.LookRotation((dst -
src), Vector3.right);
Vector3 euler = quat.get_eulerAngles();
return { euler.y, euler.x };
}
the horizontal axis(euler.y) returned from CalcEuler is perfect and rotates the hub to lock onto the specified direction. However the vertical axis(euler.x) returned from CalcEuler only works if the direction.Y value is the same as src.Y. If it isnt then itll shoot up into really high numbers past 200 and even sometimes at 359.99.
What could I be doing wrong?
EDIT: I found something some guy did on github for his rotation. After doing Quaternion.Lookrotation he did this
euler.x = (src.y < dst.y) ? (-360.f + euler.x) : euler.x;
however this does not change anything for me
SOLVED: Both answers fix the problem