Problem with Quaternion and Euler Angles
I receive the input from an xbox controller to move the camera into a Vector3:
camMove = new Vector3(Mathf.Clamp(camMove.x + input.y * -1 * sensitivity, -90f, 90f), camMove.y + input.x * sensitivity, 0 );
Then, if I make a score, the camera looks at the score stats in a tv of the game. BUT, I want to let the player keep moving their stick from that position/rotation.
Quaternion daRot = Quaternion.LookRotation(lookatStat.transform.position);
mainCam.transform.rotation = daRot;
camMove = mainCam.transform.eulerAngles;
mainCam.transform.eulerAngles = camMove;
So, what happens is that the camera looks at the score, and when it updates the euler angles, it just looks to the ground really abruptly, as if the euler angles or the rotation was different than what I supposedly saved in camMove.
Why is this happening?
what are you suppost to be doing here?
cam$$anonymous$$ove = mainCam.transform.eulerAngles;
mainCam.transform.eulerAngles = cam$$anonymous$$ove;
since both lines just makes no sense, you save the transform eulerangles of the actual camera and in the next line update the eulerangles with the same vector?
this line is always beign updated cause the controller input is cam$$anonymous$$ove: mainCam.transform.eulerAngles = cam$$anonymous$$ove;
But, when I make a score, I rotate the camera with LookAt to the score tv. Now, what I do is that I save the euler angles from the main camera into the cam$$anonymous$$ove variable:
cam$$anonymous$$ove = mainCam.transform.eulerAngles;
So that in the next line: mainCam.transform.eulerAngles = cam$$anonymous$$ove; starts from that position saved and starts recording the controller inputs.
u have a mess with assign and know the purpose of variables, maybe u need to check the classic algoritms to view a wise organization of variables, u initialize daRot
with the position of the score, and later use it to set rotation on cam, well its ok but u can do this on just one step
mainCam.transform.LookAt(lookatStat.transform);
u later give the value to the cam position to u buffer cam$$anonymous$$ove replacing the value calculated checking the commands, and also give it to camera position, so with this lines u arent doing nothing, just reasign the same value
cam$$anonymous$$ove = mainCam.transform.eulerAngles;
mainCam.transform.eulerAngles = cam$$anonymous$$ove;
I think u just want to do some
mainCam.transform.forward += cam$$anonymous$$ove;
and leave the all rotation calculus to unity engine.
hope this helps.
It´s just that actually these lines:
cam$$anonymous$$ove = mainCam.transform.eulerAngles;
mainCam.transform.eulerAngles = cam$$anonymous$$ove;
are like this:
if (lookAtScore)
{
Quaternion daRot = Quaternion.LookRotation(lookatStat.transform.position, Vector3.up);
mainCam.transform.localRotation.SetLookRotation(lookatStat.transform.position);
cam$$anonymous$$ove = mainCam.eulerAngles;
lookAtScore = false;
}
because I store the euler angles from the main camera when they are looking at the score into the cam$$anonymous$$ove variable. The cam$$anonymous$$ove variable also stores the controller inputs, so that is why this next:
mainCam.transform.eulerAngles = cam$$anonymous$$ove;
so that now we can start checking the controller inputs from the position where our mainCamera is. I forgot to put those brackets, but I still don´t get why the camera starts looking below after I stored the euler angles of the main camera into cam$$anonymous$$ove.
I think LookRotation is being used wrong. It takes a "vector" arrow as input, for example LookRotation(target-source). Using it with only a target gives you the rotation if you're sitting at (0,0,0).
Your answer
Follow this Question
Related Questions
Delayed LookAt, but only on one axis 1 Answer
How to make a 2D sprite rotate towards a specific point while facing perpendicular to the camera ? 1 Answer
How to use Quaternion.slerp and Quaternion.LookRotation with a child gameobject 0 Answers
How to convert Quaternions to Euler angles with different order? 0 Answers
Instantiate object in orientation of previously instantiated object 1 Answer