- Home /
How to rotate object's y-axis with mouse position on screen ?
Hi every one. I'm making a third person game. When I move cursor, I want to player rotate y - axis with mouse position on screen. Anyone have a idea ?
Answer by tmalhassan · Sep 16, 2017 at 03:53 AM
Hello.
For 3D games:
Take a look at this: http://wiki.unity3d.com/index.php?title=LookAtMouse
For 2D games:
Follow this thread: http://answers.unity3d.com/questions/798707/2d-look-at-mouse-position-z-rotation-c.html
or
Make your life easier and follow this Youtube tutorial: https://www.youtube.com/watch?v=_XdqA3xbP2A
Hope this is what you need. Cheers!
Thank you your answer, it's so great. But it isn't like my idead. Look like this : Hope your answer soon !
Oops. I just assumed that you wanted 3D. $$anonymous$$y apologies. for 2D, it's way simpler. Basically, the idea is to calculate the angle degree and then use transform.rotation to make the object look at the mouse. I updated the answer. Good luck :)
(Updated answer) found a simple Youtube tutorial. it will help a lot.
Your answer
Follow this Question
Related Questions
Firing projectiles on the XZ Plane 2 Answers
Problem with unity ads 0 Answers
unity ads after google play publishing ?? 0 Answers
WebGL compiler errors 0 Answers
problem with button touch zone 0 Answers