- Home /
Question by
fighder · Sep 11, 2015 at 03:10 PM ·
2d gamecharactercontrollerquaterniontopdownquaternion.lookrotation
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:
Comment
Your answer
Follow this Question
Related Questions
how to aim an object at another object 1 Answer
Third person Character Control 0 Answers
2D topdown combat collider vs OverlapBox etc... 1 Answer
Character movement always faces forwards 1 Answer
Player doesn`t jump, please help! 1 Answer