Hi, I building a game Geometry Wars like; I want to be able to rotate the "player" when moving the mouse to aim to the enemies. I'm using the MouseLook script as an start point but it's not working for me as the "player" rotating is not in synch with the mouse movement.
Answer by Jesse Anders
Sep 07, 2010 at 11:41 AM
Orienting an object towards the mouse position is a topic that's discussed frequently in the forums. Try searching the forums for (e.g.) 'aim at mouse'. Also, check out the EvacCity tutorial, as it shows how to do this (including code).
Note that if the player is not always located at the center of the screen, you may need to tweak things a bit. In short, the player and mouse position need to be expressed in the same space for the purpose of determining the rotation (this could be screen space, or world space - whichever you prefer). Once you have the positions in the same space, compute the vector from the player position to the mouse position, and then use Transform.LookAt() to aim the player at the cursor. (You can also compute the angle using Atan2() and rotate the player accordingly if you prefer.)
Answer by Dimitar
Dec 27, 2010 at 09:29 AM
If You haven't found anything try to get some ideas from that demo island they made. The camera could give you some "Lightbulb"
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
No one has followed this question yet.
restrict mouselook X movement script does not work
Using quaternion for mouse movement?
Screen.lockCursor messes my rotation
Lock rotation on Z Axis
Turning off character control when window open