0
\$\begingroup\$

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.camerarotation scriptPlayerFollowCameraPlayer object

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Please share code as text, not as an image. Visit the help center for code formatting guidance. \$\endgroup\$
    – DMGregory
    Commented Jul 14, 2023 at 7:53

1 Answer 1

0
\$\begingroup\$

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.

\$\endgroup\$
3
  • 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\$
    – Bogdan
    Commented Jul 15, 2023 at 21:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .