Player only rotates 180 degrees instead of 360 relative to mouse position

I’m trying to get my player to rotate 360 degrees in the direction of the mouse but that’s not being achieved. Any help would be much appreciated, thanks in advance.

Relevant piece of my code:

public class CharacterController : MonoBehaviour {

    public float speed;
    private float maxSpeed = 5.0f;
    public float camSpeed;

    private Rigidbody rb;
    private Camera cam;

    void Start () {
        cam = GameObject.Find("Main Camera").GetComponent<Camera>();
        rb = GetComponent<Rigidbody>();
    }

    void Update()
    {
        Vector3 mousePos = cam.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 20));
        Vector3 direction = Vector3.Normalize(transform.position - mousePos);

        float step = camSpeed * Time.deltaTime;

        if (transform.forward != direction)
        {
            Vector3 newDir = Vector3.RotateTowards(transform.forward, direction, -step, 0.0f);
            transform.rotation = Quaternion.LookRotation(new Vector3(newDir.x, 0, newDir.z));
        }

       
       
    }
}

Couple things:

  1. cam = GameObject.Find("Main Camera").GetComponent<Camera>() can be shortened to cam = Camera.main

  2. From the Vector3.RotateTowards docs: “If a negative value is used for maxRadiansDelta, the vector will rotate away from target/ until it is pointing in exactly the opposite direction, then stop”.

  3. Use lots of Debug.Log to help figure out what’s going on each frame.

Still only 180 degrees of rotation.

Ok i figured out that it was my Cameras cause i had 2 cameras one inside the player and the main camera so i switched to the camera inside the player but the problem now is that my player will adjust to rotate towards my mouse but it does not stop there it just keeps spinning and spinning.