C# FPS script camera look error

So i was making an FPS game(cause my creativity knows no bounds) and stumbled across an annoying error. everything was working fine until i added wallrunning to my character. the wallrun code is incomplete, but anyway, the camera only rotates on the y axis. it can only look around. it can’t look up and down. it was working fine earlier but now it just doesnt rotate on the X axis. i tried replacing my current code with the code i had first written, while the camera rotated correctly. it still does not work. i suspect there is nothing wrong with the code, but i’ll post it here anyway.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    //vars
    [Header("Look")]
    float verticalLookRotation;

    public float mouseSensitivityX = 2f;
	public float mouseSensitivityY = 2f;
    public Transform fpsCam;
    bool cursorVisible = false;

    [Header("Movement")]

	public float walkSpeed = 10.0f;
    public float airStrafe = 7f;
    public float jumpForce = 250.0f;
	public bool grounded;
    public bool jump;
	public LayerMask groundedMask;
	Vector3 moveAmount;
	Vector3 smoothMoveVelocity;
	
	Rigidbody rb;	

    public float landingImpactVelocity = 1f;

    [Header("Animation")]

    public Animator camAnimator;

    [Header("Debug")]
    public float playerMagnitude;
    
    [Header("Wallrunning")]
    public Transform wallrunRay;

    //getVars
    void Start () {
		fpsCam = Camera.main.transform;
		rb = GetComponent<Rigidbody> ();
		LockMouse();
        camAnimator = GetComponentInChildren<Animator>();
	}

    //update
    void Update () {

        //debug
        playerMagnitude = rb.velocity.magnitude;
		
        // rotation
		transform.Rotate (Vector3.up * Input.GetAxis ("Mouse X") * mouseSensitivityX);
		verticalLookRotation += Input.GetAxis ("Mouse Y") * mouseSensitivityY;
		verticalLookRotation = Mathf.Clamp (verticalLookRotation, -60, 60);
		fpsCam.localEulerAngles = Vector3.left * verticalLookRotation;

		// movement
        if(grounded){
            Vector3 moveDir = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical")).normalized;
		    Vector3 targetMoveAmount = moveDir * walkSpeed;
		    moveAmount = Vector3.SmoothDamp (moveAmount, targetMoveAmount, ref smoothMoveVelocity, .15f);
        } else {
            Vector3 moveDir = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical")).normalized;
		    Vector3 targetMoveAmount = moveDir * airStrafe;
		    moveAmount = Vector3.SmoothDamp (moveAmount, targetMoveAmount, ref smoothMoveVelocity, .15f);
        }
		
		// jumping
		if (Input.GetButtonDown ("Jump")) {
			if (grounded) {
				rb.AddForce (transform.up * jumpForce);
			}
		}

        //ground check
		Ray ray = new Ray (transform.position, -transform.up);
		RaycastHit hit;

		if (Physics.Raycast(ray, out hit, 2 + .1f, groundedMask)) {
			grounded = true;
		}
		else {
			grounded = false;
		}

		//mouse locking
		if (Input.GetKeyUp(KeyCode.Escape)){
			if (!cursorVisible) {
				UnlockMouse ();
			} else {
				LockMouse ();
			}
		}

		//sliding
		

        //wallrunning
        //right raycast
        Ray rayR = new Ray (wallrunRay.position, wallrunRay.right);
		RaycastHit hitR;

		if (Physics.Raycast(rayR, out hitR, 1 + .1f)) {
			Debug.Log("Wallrun right");
            rb.useGravity = false;
            camAnimator.SetBool("wallrunR", true);
		}
        else{
            rb.useGravity = true;
            camAnimator.SetBool("wallrunR", false);
        }

        //left raycast
        Ray rayL = new Ray (wallrunRay.position, -wallrunRay.right);
		RaycastHit hitL;

		if (Physics.Raycast(rayL, out hitL, 1 + .1f)) {
			Debug.Log("Wallrun left");
            rb.useGravity = false;
            camAnimator.SetBool("wallrunL", true);
		}else{
            rb.useGravity = true;
            camAnimator.SetBool("wallrunL", false);
        }

	}
    //move the player
    void FixedUpdate() {
      rb.MovePosition (rb.position + transform.TransformDirection (moveAmount) * Time.fixedDeltaTime);
		
	}
    //unlock mouse
	void UnlockMouse() {
		Cursor.lockState = CursorLockMode.None;
		Cursor.visible = true;
		cursorVisible = true;
	}
    //lock mouse
	void LockMouse() {
		Cursor.lockState = CursorLockMode.Locked;
		Cursor.visible = false;
		cursorVisible = false;
	}
    //landing impact
    void landingImpact(){
        camAnimator.SetTrigger("Land");
        return;
    }
    //landing impact check
    void OnCollisionEnter(Collision collInfo)
    {
        if(collInfo.transform.gameObject.layer == 9)
        {
            landingImpact();
        }
    }

}

help pls

You can try to extract the camera controls from the code you shared and write the following as a separate script. You must add the script you just wrote to the camera object. I hope it works, I tried it in my last project :slight_smile:

using UnityEngine;

public class CameraController : MonoBehaviour
{
    [SerializeField] private Transform player;

    [SerializeField] private float mouseSensitivity = 100f;

    private float rotX;
    private float rotY;

    private float minX = -60;
    private float maxX = 60;

    void Update()
    {
        rotX -= Input.GetAxis("Mouse Y") * Time.deltaTime * mouseSensitivity;
        rotY += Input.GetAxis("Mouse X") * Time.deltaTime * mouseSensitivity;

        rotX = Mathf.Clamp(rotX, minX, maxX);
        transform.GetChild(0).localRotation = Quaternion.Euler(rotX, 0, 0);
        
        transform.localRotation = Quaternion.Euler(0, rotY, 0);
    }

   
}