- Home /
Camera Rotation Script Totally Screwed Up
So I have this script in which I want to rotate my camera by 45 degrees on the X. But when I put it in and run the code, it turns 3.5 degrees on the X while the Y and Z suddenly turn 180.
I did try removing the 180 degrees and that just caused it to rotate even more.
var target : Transform;
var zdistance : float;
var ydistance : float;
var obj : GameObject;
//obj = gameObject;
function Start() {
transform.position.z = -3.5;
transform.rotation.x += 45;
/*
transform.rotation.y -= 180;
transform.rotation.z -= 180;
*/
}
function Update() {
transform.position.y = target.position.y + 5;
transform.position.x = target.position.x;
}
In your update function you change the x and y equal to whatever the transform properties of target is (well the y is equal plus 5).
So anything you do in your start function is pretty much void due to the fact you override it every frame in your Update function.
Whatever "target" is has a x and y of -180
In update, I'm only changing the position, not the rotation.
Answer by robertbu · Aug 12, 2013 at 03:30 AM
'transform.rotation' is a Quaternion, a non-intuitive, 4D construct. You should not directly access the x,y,z or w components unless you have a firm grounding in Quaternions. You can use transform.eulerAngles, but you should not assign components independently (you can end up with strange rotations). Since your code is a relative movement, you can do:
transform.Rotate(45.0,0,0);
Your answer
Follow this Question
Related Questions
how can a camera zoom into a game object? 3 Answers
Lerp Rotation broken 1 Answer
fixed rotation around object 1 Answer