- Home /
How do you make a Tps cam with RotateAround around the X and Y axis without rotating on the Z axis?
Hello, so I have been working on a game and have done some research on this topic, but no one seems to know the answer. I am trying to Rotate the camera around the player around the X and Y axis. Here is my code:
private void Update()
{
if (Input.GetMouseButton(1))
{
mainCam.transform.RotateAround(body.transform.position, Vector3.up, Input.GetAxis("Mouse X") * 100 * Time.deltaTime);
mainCam.transform.RotateAround(body.transform.position, body.transform.right, Input.GetAxis("Mouse Y") * 100 * Time.deltaTime);
}
}
After running this code the Z axis will eventually also change value. I get why it does this, but donot know how to fix this. If anyone knows please let me know.
Answer by Satton38 · Sep 03, 2019 at 01:34 AM
How about adding a code to fix the Z axis?
Vector3 rot = mainCam.transform.eulerAngles;
mainCam.transform.eulerAngles = new Vector3(rot.x, rot.y, 0);
Your answer
Follow this Question
Related Questions
How to "clamp" a y rotation in unity? 0 Answers
Swipe angle and Rotation of camera to movement 1 Answer
Why does the direction of the axis changes behaviour in Quaternion.AngleAxis? 0 Answers
How do I rotate player's camera to peak around objects. (first person shooter leaning) 1 Answer
LookRotation or euler angle object rotation towards 1 Answer