- Home /
Camera locks on y axis on start
I've had this problem for a while now and it's very slowly making me go mad. We made a game and everything works fine, except the camera. When you open the game you press Start with your mouse, the camera will now pan down to a first person position. The mouse is hidden and the player should now be able to move the camera around as you expect. The only problem is that it is locked on the y axis (horizontal movement works just fine). Here's the script I'm using (it's the default MouseLook script with some minor additions):
function Update(){
if(!menu.start && !menu.isPaused || menu.isAnimating){
Screen.showCursor = false;
Screen.lockCursor = true;
}
else if(menu.isPaused){
Screen.showCursor = true;
Screen.lockCursor = false;
}
if(!menu.start && !menu.isPaused && !menu.isAnimating){
if(axes == RotationAxes.MouseXAndY){
var rotationX : float = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY * invertedcam;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = Vector3(-rotationY, rotationX, 0);
}
else if(axes == RotationAxes.MouseX){
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
}
else{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = Vector3(-rotationY, transform.localEulerAngles.y, 0);
}
}
}
You can play the game here: http://www.kongregate.com/games/Aceria620/fragments-of-him The bug occurs once you press Start and the camera pans down.
Answer by aldonaletto · May 07, 2013 at 12:54 PM
From your web game, it seems that you've forgot to initialize invertedcam - this way it starts with 0, and no vertical movement occurs. Once I set the Y direction in the menu, the camera vertical control started to work.
I didn't even think of that, but that makes 100% sense. Thanks a lot!