look at with screenPointToRay

I have to rotate the player based on where I point the mouse. The problem is in the perspective of the room. If the camera is on, the player works correctly. If instead it is inclined (what is needed for me) the lookAt does not work properly. Can someone help me?

    void Update()
    {
        Ray mousePos = viewCamera.ScreenPointToRay(Input.mousePosition);
     
        RaycastHit hit;
        //Vector3 dir = (mousePos.origin - Vector3.forward).normalized;
     
            if (Physics.Raycast(mousePos, out hit))
            {

                hit.point = mousePos.direction;
                // + Vector3.up * transform.position.y);
                Debug.DrawRay(mousePos.origin, hit.point * 30, Color.red);
                Vector3 mod = new Vector3(mousePos.direction.x, 0, mousePos.direction.z);
                this.transform.rotation = Quaternion.LookRotation(mod);
            Debug.Log(mod);
            }
}

Don’t modify the hit.point value and use that to form your look vector. This should work:

Vector3 mouseOnPlane = new Vector3(hit.point.x, 0f, hit.point.z);
Vector3 playerOnPlane = new Vector3(player.transform.position.x, 0f, player.transform.position.z);

player.transform.rotation = Quaternion.LookRotation(mouseOnPlane - playerOnPlane);

thanks for the help. but why with LookAt it does not work?

I don’t see why transform.LookAt wouldn’t work, if you fed it the raycastHit.point.