Need help with rotating object

I am going for a 3rd person camera and i want to get the camera to rotate based on the mouse’s X / Y input.
I have created a cinemachine free look camera to follow the object around, and it’s focusing on a child within the game character (the white capsule).

The idea is that when i want the camera to rotate, the script will rotate the white capsule to which the camera is tied and achieve the same goal. So i wrote this script:

When i comment out one of the 2 lines and let each one run on each own, the camera rotates properly (around the X or Y axis respectively). But when they run simultaneously, the capsule also rotates around the Z - axis:

I am not sure how to fix this either. I tried setting the Z rotation to 0 afterwards but it doesn’t work. I have also tried with the capsule unparented and the issue is still the same.

What am i doing wrong?

You can just paste images and code (make sure to use code tags) directly into the forum, no need to go through a third-party image hosting service.

1 Like