Getting a 2d Character to Follow the mouse

Im trying to get my charachter to follow my mouse cursor in a 2d like way. When the cursor is in front of him he looks to the front and if the cursor is in back he turns around. Right now all he does is turn and look at the camera like the mouse pointer is to the side of him. I had an idea of makeing a plane object and just having him transform.LookAt it but I cant get the plane to follow the mouse. So if anyone has any ideas please help. I have NO working code right now so I cant post what I have sorry. Thanks in advance.

Have a look at the “TapControl” script that comes with the Penelope tutorial.

Um… Yes, but the code could give you some ideas about how to build a script that follows the mouse click…

(Basically, what I’d try is placing a Empty gameObject at the place on your mesh where the mouse clicks, then have your character lookAt that Empty gameObject position and move to it…)

Okay, I’m officially confused. I now think you’re wanting the character to follow the mouse around, in which case you probably want to use a OnMouseOver function, but honestly, I’d have to see what code you are using to get some idea of what it is you’re actually trying to do.

Has this question been answered already? , in case not to attach an object to your mouse is quite easy. Use Camera.mainCamera.ScreenToWorldPoint(screenPos);

Example code:
private void attachObjectToMouse () {
Vector3 screenPos = Input.mousePosition;
screenPos.z = 5;
Vector3 worldPos = Camera.mainCamera.ScreenToWorldPoint(screenPos);
gameObject.transform.position = worldPos;
}

Call the above function inside ‘void Update ();’ of the object you want to attach to the mouse. ‘screenPos.z’ defines the depth at which you want your object to be from the camera. i.e. in this case 5 units in front of my camera. Also make sure that this value is a minimum of 2-3 units greater than the ‘near’ value of your camera otherwise you wont see the object in your game scene. The above code will work only if the camera you are using is the default MainCamera. In case you wish to use your own camera replace ‘Camera.mainCamera’ according to your needs.