Camera RotateAround, in different angles it moves X instead of Y
Hello there,
Today is 4th day I am started doing things in unity, one thing that is too much for my mathematics logic is axes (i am very bad in mathematics).
I have written a script that can move camera around player (left and right) based on mouse movement (0/1 button is pressed). Then I have added movement around (up and down).
Now If camera rotation is around Y(-55) and around Y(90), then if I move mouse up and down, it rotates the camera to left/right slowly, as soon as camera Y rotation is far away from Y(-55) and Y(90) it moves correctly.
Here is my code for camera rotation around player (note the player object is "this" and camera is "c")
// Rotate camera if some mouse s used
if (Input.GetMouseButton(1) || Input.GetMouseButton(0))
{
UnityEngine.Cursor.visible = false;
// If holding right mouse, then camera follows player movement rotation
// Where player movement rotation is done by mouse movement
// So if player is holding right button dissalow left-right rotation of camera
if (!Input.GetMouseButton(1))
{
// Move around left right
c.transform.RotateAround(transform.position, Vector3.up, Input.GetAxis("Mouse X") * 1f);
}
// Move around up down
c.transform.RotateAround(transform.position, Vector3.right, Input.GetAxis("Mouse Y") * 1f);
// Because of wrong Z of camera caused previous action (after a while game is upside down)
// when moving Up and Down this will fix this
c.transform.LookAt(transform);
}
else
{
UnityEngine.Cursor.visible = true;
}
I will be happy if you can help me to solve this problem, and much happier if you can also why it happens.
Your answer
Follow this Question
Related Questions
Making the player the camera's axis of rotation. 0 Answers
Make character face movement direction 0 Answers
player not following camera rotation in vr 0 Answers
Camera Rotation Around Player 1 Answer