- Home /
How to look up and down with mouse
I have a start of a camera look script and I have it to let me go left and right . How do I allow it to go up and down?
C#
float horizontal = Input.GetAxis ("Mouse X") * rotateSpeed;
target.transform.Rotate (0, horizontal, 0);
float desiredAngle = target.transform.eulerAngles.y;
Quaternion rotation = Quaternion.Euler (0, desiredAngle, 0);
transform.position = target.transform.position - (rotation * offset);
transform.LookAt (target.transform);
Answer by Inok · Nov 05, 2015 at 08:37 PM
float horizontal = Input.GetAxis ("Mouse X") * rotateSpeed;
float vertical = Input.GetAxis ("Mouse Y") * rotateSpeed;
target.transform.Rotate (vertical, horizontal, 0);
float desiredAngleH = target.transform.eulerAngles.y;
float desiredAngleV = target.transform.eulerAngles.x;
Quaternion rotation = Quaternion.Euler (desiredAngleV, desiredAngleH, 0);
transform.position = target.transform.position - (rotation * offset);
transform.LookAt (target.transform);
Ive tried it before, but the problem is the whole character moves as in if I look down, the player moves too
Answer by Eno-Khaon · Nov 05, 2015 at 11:03 PM
Some of Unity's standard scripts include a fairly straightforward solution to this. Their first-person control scripts tend to keep one key point in mind.
You need scripts on two objects: One is for your character, so turning left and right turns the character as well. The other is for your camera, to look up and down without tilting your character up and down with it.
Your answer
Follow this Question
Related Questions
Rotating object based off mouse input 1 Answer
Rotating a camera that is already rotated on Z axis 0 Answers
Flip over an object (smooth transition) 3 Answers
Rotating Player 0 Answers
How does LookRotation work in relation to ray cast? 1 Answer