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);
}
}