- Home /
Rotate camera to lean
Hi,
I am trying to achieve something quite simple and yet I can't figure it out. I am quite new to scripting as well.
In my scene I dropped a First Person Controller. When I press the Q button I want the camera to rotate to the left as the player is leaning/looking around a corner. Same for the E button for the right side.
I created a new javascript and attached it to the Main Camera of the First Person Controller.
So I wrote the script below which doesn't set the rotation (z) at 10 but at 165 and also changes the rotation (x). Any idea's?
var leanLeft : boolean = false;
function Update () {
if(Input.GetKey("q")) {
doLeanLeft();
}
}
function doLeanLeft() {
if(leanLeft == false) {
leanLeft = true;
transform.rotation.z = 10;
leanLeft = false;
}
}
Answer by nventimiglia · Dec 03, 2012 at 08:27 PM
Uses Euler Angles.
transform.rotation = Quaternion.Euler(10,0,0);
I changed the "transform.rotation.z = 10;" with your line but I kind of get the same result.
Your answer
Follow this Question
Related Questions
How to access the light component on a camera object? 1 Answer
Converted MouseLook from C# to Java problems 2 Answers
Camera Movement (One Position to Another) 1 Answer
Screen Position Out of view frustum error while zooming in gun 0 Answers
Switching Cameras - Confusion with Two Code Samples 2 Answers