- Home /
Logical Camera errors...
Ok, so im having this error with my Camera script.. I know what the issue is juts not how to solve it. It orbits around the player, and if i orbit right, and then up a bit and then right again, it starts orbiting diagonally.
this top view diagram shows the degree at which it can rotate around the player. So a full 360°.
this front view diagram shows the degree at which it can rotate up and downwards whilst looking at the player. about 40°..
as you can see this is what is occurring if i rotate right then up then right. If i do that i just want it to continue on a 'locked' axis.
if (Input.GetKey(KeyCode.LeftArrow)) {
transform.Rotate(0,Time.deltaTime * 100,0);
}
else if (Input.GetKey(KeyCode.RightArrow)) {
transform.Rotate(0,Time.deltaTime * -100,0);
}
else if (Input.GetKey(KeyCode.UpArrow)) {
transform.Rotate(Time.deltaTime * 100,0,0);
}
else if (Input.GetKey(KeyCode.DownArrow)) {
transform.Rotate(Time.deltaTime * -100,0,0);
}
sorry if i havent explained it properly its hard. hopefully the pictures give you guys some idea of whats occurring.
Answer by pako · Mar 15, 2014 at 09:57 AM
I don't understand 100%, but it seems to me that this happens because you are rotating the camera using local axis rather than world. Try specifying Space.World as the last parameter in your Rotate statements, see:
http://docs.unity3d.com/Documentation/ScriptReference/Transform.Rotate.html
e.g.
if (Input.GetKey(KeyCode.LeftArrow)) {
transform.Rotate(0,Time.deltaTime * 100,0, Space.World);
}
that has given me some crazy stuff. Ill try to explain better, basically if i rotate horizontally it will be (for example) (0,70,0) upward (10,0,0) so the final rotation will be (10,70,0) correct? yes. So now if i continue again on the horizontal rotation it will be slanted..
hold on i have fixed it, i accidently put your solution on the vertical one. Thanks this has worked.