- Home /
The question is answered, right answer was accepted
Free camera look question
I am making a space game where I want the player to be able to navigate a 3d map of all the stars. For this I made a simple script that translates the mouse X and Y axis into a change in localEulerAngles. It works perfectly, however when you move the mosue upwards and "flip" upside down, the movement is inverted. This makes total scense of course, but I don;t know how to fix it.
Here is my code
xRot += Input.GetAxis("Mouse X") * xSensitivity;
yRot -= Input.GetAxis("Mouse Y") * ySensitivity;
Vector3 newRot = new Vector3(yRot, xRot, 0);
transform.localEulerAngles = newRot;
Anyone who can help me?
Many thanks!
Answer by Avanak · Feb 16, 2015 at 09:18 PM
I found the answer for myself. I used Vector3.up and Vector3.left to generate rotation.
transform.Rotate(Vector3.up * Input.GetAxis("Mouse X") * xSensitivity);
transform.Rotate(Vector3.left * Input.GetAxis("Mouse Y") * ySensitivity);
Anyway, many thanks for the help!
Answer by giulio-pierucci · Feb 16, 2015 at 11:04 AM
Depends how do you want to link mouse to moviment.
You mey use transform.Rotate instead transform.localEulerAngles = newRot;
http://docs.unity3d.com/ScriptReference/Transform.Rotate.html
This works with less lines of code, but it still inverts the camera movement when I "flip" the camera upside down.
Follow this Question
Related Questions
How to make my Camera Controller look at target 0 Answers
Unity - Dancing Ball World camera following and rotating system 1 Answer
Would anyone teach me how to create camera movement and look controls? 2 Answers
Cinemachine input axis camera movement,cinemachine input axis control with script 1 Answer
How to allow camera to complete an upside down rotation while using LookAt() 0 Answers