Camera rotates left and right instead of the player

I have a playerController script attached to the player object. I put the main camera under the player object so the player is always the center of the camera. Now the script allows for left and right movement and also jumping (double jumping is allowed). When I run the game, the player jumps normally but when i move left and right, the camera itself rotates and not the player. What am I doing wrong?

here is the playerController Script:

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour
{
    public float moveSpeed;
    public float jumpHeight;
    public Transform groundCheck;
    public float groundCheckRadius;
    public LayerMask whatIsGround;
    private bool grounded;
    private bool doubleJump;
    
    void FixedUpdate()
    {
        grounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround);
    }

    void Update()
    {
        if (grounded)
        {
            doubleJump = false;
        }

        if (Input.GetKeyDown(KeyCode.Space) && grounded)
        {
            GetComponent<Rigidbody2D>().velocity = new Vector2(0, jumpHeight);
        }

        if (Input.GetKeyDown(KeyCode.Space) && !doubleJump && !grounded)
        {
            GetComponent<Rigidbody2D>().velocity = new Vector2(0, jumpHeight);
            doubleJump = true;
        }

        if (Input.GetKey(KeyCode.LeftArrow))
        {
            GetComponent<Rigidbody2D>().velocity = new Vector2(-moveSpeed, GetComponent<Rigidbody2D>().velocity.y);
        }

        if (Input.GetKey(KeyCode.RightArrow))
        {
            GetComponent<Rigidbody2D>().velocity = new Vector2(moveSpeed, GetComponent<Rigidbody2D>().velocity.y);
        }
    }
}

Thank you.

When i move left and right, the camera itself rotates and not the player. What am I doing wrong?

It’s hard to tell. But I would guess that the player rotates (and thus the camera too) when the rigidbody start rotating due to physics interactions. The net visual effect would be that it would appear as if the world moves and rotates and the player is stuck in one place on the screen.

If you want the camera to just follow the player and not be affected by the players rotations, unparent the camera from the player and parent it into a new game object you call camera root or something and add a script to the root that sets:

transform.position = player.position;

Then you can easily adjust positioning of the camera relative to the root that follows the player if you need.