I've recently started work on a 3rd person game and want the camera (cinemachine virtual camera) to rotate with the mouse while following the cinemachine camera, it would be best described as when you "aim in" in fortnite and your player is locked to where you are aiming and your player and camera will rotate with your mouse not w a s d. Here is my code that I currently have, it allows me to follow the player like I want but only rotates the camera on the x axis and not the y. I've tried a multitude of different script variations to try to get it to work. Pictured below is my script and my CinemachineVirtualCamera I have set up, along with the player object. I've watched just about every tutorial on camera movement but none cover the issue I'm having.
Why does my unity Cinemachine camera that follows the mouse only rotate on the x axis not the y axis
1 Answer
\$\begingroup\$
\$\endgroup\$
3
Line 30 remove and paste it in Start or Awake. Because each frame you reset rotation of camera. You do not need to reset it if you want to rotate around Y axis.
-
1\$\begingroup\$ This answer would be better if it explained why this change solves the problem. \$\endgroup\$– DMGregory ♦Commented Jul 14, 2023 at 23:09
-
\$\begingroup\$ he explained it great \$\endgroup\$ Commented Jul 15, 2023 at 21:08
-
\$\begingroup\$ Ye I explained it after read comment. I just edit answer. Is it good idea or better do not modify it? Because else comments pointing on original answer not on modified. I didn't test it in Unity so my answer could be wrong. \$\endgroup\$– BogdanCommented Jul 15, 2023 at 21:41