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...

–

1 Answer

1

Try transform.LookAt()

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.

–