Horizontal camera rotation restriction

Hello all,

I am on implementing the player camera. I have implemented so far the vertical rotation restriction, so that the player cannot rotate his head 360 °. This works perfectly. Now for a specific case I need to do also a restriction on the horizontal axis, so that the player cannot move the head/camera left or right at all. I used the same approach as for the vertical rotation, but this time it doesn’t work. And I am not seeing the error there. Can somebody pls help? What am I doing wrong?

Thank you
Huxi

Try putting the code in a formatted way instead of a screenshot , it’s already text so just copy/paste.
Maybe it’s because you’re claming the value to 0 ? in the line Mathf.Clamp(yRotation , 0,0,)

Where and when are you calling RestrictHorizontalCameraMovement() ?

You are also doing the following:

RestrictHorizontalCameraMovement()
{
   transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
   player.Rotate(Vector3.right * mouseY):
}

to get your desired outcome I recomend changing the code of Update to a separate function called CameraUpdate() and change Update to the following:

public bool restrictHCamMovement = false;

protected void Update()
{
    CameraUpdate();
    if(restrictHCamMovement) RestrictHorizontalCameraMovement();
}

changing the bool should have the desired effect.

Hello, so I have figured out, that I actually should not restrict the camera, but the whole player. Because when I am rotating left / right, then I am rotating the whole player, not just the camera. Sorry, my bad. Huxi