Character looking at opposite direction of mouse

So I used the following for my 2d top down character controllers to look at the mouse, but I recently realized the code should’ve been wrong:

mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

dir = transform.position - mousePos;

Quaternion rotation = Quaternion.LookRotation(dir,Vector3.forward);

transform.rotation = rotation;

transform.eulerAngles = new Vector 3 (0 ,0 ,transform.eulerAngles.z );

Note the code works as intended for me, but what bothers me is that the code should’ve been wrong at the second line:

dir = transform.position - mousePos;

when direction should’ve been calculated the other way around:

dir = mousePos - transform.position;

which caused my characters to be rotating the opposite way instead, anyone can explain my own code to me D:

bump, really need help understanding D: