- Home /
Very weird rotation axis bug
Hi,
I've been getting a very strange bug of sorts (not even sure if it is a bug or not) on a camera control script. It's working how a want, to an extent. The current code I have here rotates around the player fine (on the Y axis), but I've been trying to add the ability to rotate the camera up or down to view higher or lower objects (X axis). The problem is that this has been causing rotation on my Z axis too, making the camera end up in all sorts of angles I don't want it in. Here, however, is where it gets weird... I put transform.rotation.z = 0;
into the update function, but this caused my camera to rotate on an axis diagonal to the X axis. Below is my code:
#pragma strict
var characterMain : Transform;
var yOffset : float;
var XrotateSensitivity : float;
var YrotateSensitivity : float;
function Update ()
{
transform.position = characterMain.position;
transform.position.y = characterMain.position.y + yOffset;
if(Input.GetAxis("Mouse X") < 0)
{
transform.Rotate(0,Input.GetAxis("Mouse X")*XrotateSensitivity,0);
}
if(Input.GetAxis("Mouse X") > 0)
{
transform.Rotate(0,Input.GetAxis("Mouse X")*XrotateSensitivity,0);
}
if(Input.GetAxis("Mouse Y") < 0)
{
transform.Rotate(Input.GetAxis("Mouse Y")*YrotateSensitivity,0,0);
}
if(Input.GetAxis("Mouse Y") > 0)
{
transform.Rotate(Input.GetAxis("Mouse Y")*YrotateSensitivity,0,0);
}
}
I have this script attached to an empty to which my camera is childed.
If anyone knows how to fix this, or can suggest a better way to do what I'm trying to do, I'd greatly appreciate any help.
Thanks.
Answer by Raresh · Apr 26, 2015 at 08:18 PM
I think this is a case of "Gimbal Lock". You should give it a search. https://www.youtube.com/watch?v=zc8b2Jo7mno
Thanks, I've done some digging and came to a conclusion :)