How to rotate camera based on player input
Hello at all. I would like to rotate camera based on user input. I explain: when user press classic up/down arrow, player is move, but i want also rotate main camera. It is not a player follow rule. At the moment i'm trying to rotate camera from Player MOvement script, but it not works. Here my sample code
if (moveVertical > 0) {
Camera mainCam = Camera.main;
if (mainCam.transform.rotation.x <= 95) {
Vector3 target = new Vector3(mainCam.transform.rotation.x + 1, mainCam.transform.rotation.y, mainCam.transform.rotation.z);
mainCam.transform.Rotate (target);
}
}
I know i'm doing something wrong because 1) mainCam.transform.rotation.x not contain "classic" value from 1 to 360 degree. I read something about quaternion 2) rotation works but it continue to rotate because of problem nr 1
Thanks in advance for any ..tips ! Bye
Hi. It is not clearly undestandable what exactly your problem is here.
I would like to rotate camera based on user input
-> http://answers.unity3d.com/questions/664282/use-inputmouseposition-to-rotate-camera.htmlmainCam.transform.rotation.x not contain "classic" value from 1 to 360 degree
->Because it's a quaternion: http://answers.unity3d.com/questions/799824/oafatwhy-does-transformrotationx-45-not-work.html
If you want angles in degrees, use eulerAngles or localEulerAngles respectively. If you already read that this has to do with quaternions, why are you wondering that it won't work? ;)rotation works but it continue to rotate
->That's because the angle is not stored in degrees in a quaternion. It will stay between -1 and 1 so "x
I suggest you follow the official beginner tutorials before trying stuff on your own. You can find them in the Learn Section.
Have a nice day.
Your answer
![](https://koobas.hobune.stream/wayback/20220612072409im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Smooth rotation on Y axis to target pose 0 Answers
Visible Rotation from controller 1 Answer
Rotate cube as if it were floating in the sea 1 Answer
Rotating a forward vector 0 Answers