- Home /
[2D] Looking at mouse is rotated about 90 degrees.
Hello, I don't know what is wrong with this code but here it is:
Vector3 dir = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position);
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
And here is the problem:
https://imgur.com/a/LtoNc
Gameobject is rotated about 90 degrees.
Comment
Answer by TanselAltinel · Oct 24, 2017 at 08:53 AM
If you want player to look at mouse you can use this script instead:
var mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
rotation = Quaternion.LookRotation(_player.transform.position - mousePosition, Vector3.forward);
Your answer
Follow this Question
Related Questions
Cannot assign the Player to the Camera automatically 3 Answers
Camera Follow Player using a path 0 Answers
c# set main camera to player (multiplayer) 1 Answer
Player Laggs/Shakes while making movement[Android] 1 Answer
Distribute terrain in zones 3 Answers