- Home /
Player Look at Mouse Unity 4.3.1 2D
Hello, I'm making a top down 2D game in Unity 4.3.1 and I want my player to rotate/look at the mouse position. I have found and tried quite a few solutions posted on the web but none seem to work. It would appear most of the solutions are based on making a 2D game in Unity 3D as opposed to Unity 2D.
Any help would be really appreciated!!
-Captain
I think I want the player's z orientation to be directly associated with the mouse location, I'm just not sure how to do this...
Answer by areFranz · Dec 05, 2013 at 10:18 PM
Like (C#) Vector3 mousePosition = Input.mousePosition; transform.LookAt(mousePosition); or (JS) var mousePosition : Vector3 = Input.mousePosition; transform.LookAt(mousePosition);
Gave this a try and it didn't work. When I use the "LookAt" function my player entity becomes invisible. I tried replacing "Rotate" for "LookAt" but this causes the player to rotate continually which makes sense because it's rotate that much every frame as opposed to looking at the mouse and rotating to that angle every frame, which is what I want it to do.
Your answer
![](https://koobas.hobune.stream/wayback/20220613123520im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Enemy collision in 2D top down 2 Answers
2D Animation does not start 1 Answer
Top down house Help 2 Answers
How To Make An Invisible Wall That's Impossible To Get Out Of? 1 Answer